Unix Technical Forum

Parsing a SQL Statement as a parameter and executing it

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 ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 09:11 AM
coosa
 
Posts: n/a
Default 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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 09:11 AM
David Portas
 
Posts: n/a
Default Re: Parsing a SQL Statement as a parameter and executing it

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
--


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:00 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com