471,092 Members | 1,547 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

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?

Jul 23 '05 #1
1 1281
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:


David Portas
SQL Server MVP
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by .d.hos | last post: by
reply views Thread by burn_hall | last post: by
5 posts views Thread by Aleksandar Matijaca | last post: by
7 posts views Thread by Steven Bethard | last post: by
1 post views Thread by Philip Semanchuk | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.