|
Home > Archive > Microsoft SQL Server forum > June 2005 > Parsing a SQL Statement as a parameter and executing it
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Parsing a SQL Statement as a parameter and executing it
|
|
|
| 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?
| |
| David Portas 2005-06-26, 8:23 pm |
| 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
--
|
|
|
|
|