This is a discussion on Parsing a SQL Statement as a parameter and executing it within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi all, I was just wondering if it could be possible to excecute a statement which is extracted from ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi all, I was just wondering if it could be possible to excecute a statement which is extracted from variabele, Example: declare @SqlStatement varchar (100) set @SqlStatement = 'select * from company' the @SqlStatement contains the actual sql query, is it possible some how to straight away convert it into excecution? I've tried: exec @SqlStatement but exec or execute are meant to be for procedures Any idea? |
| ||||
| It is possible but not usually desirable. Dynamic code execution has potential implications for maintainability, reliability, performance, security and testing. Most of the time there are far better alternatives. The following article has more information: http://www.sommarskog.se/dynamic_sql.html -- David Portas SQL Server MVP -- |