Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to say?: EXEC @strSQL

Author  Topic 

Glynner
Starting Member

5 Posts

Posted - 2008-10-24 : 08:43:39
I want, in the course of a stored procedure, to be able to say something like:
EXEC @strSQL

The value of @strSQL will be something like "UPDATE TableX SET FieldX = 123 FROM bla bla bla" which I have built up from input parameters.

Is there a way to do this?

Sean_B
Posting Yak Master

111 Posts

Posted - 2008-10-24 : 08:49:02
is this what you're looking for ?

DECLARE @strSQl VARCHAR(500)
SET @strSQl = 'UPDATE TableX SET FieldX = 123 FROM bla bla bla'

EXEC(@strSQl)

Sean
Go to Top of Page

Glynner
Starting Member

5 Posts

Posted - 2008-10-24 : 08:58:31
Wow, just those parentheses made all the difference!
In most programming languages I've met X and (X) would evaluate to the same thing.

Thanks Sean B

Niall
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-24 : 10:01:54
quote:
Originally posted by Glynner

Wow, just those parentheses made all the difference!
In most programming languages I've met X and (X) would evaluate to the same thing.

Thanks Sean B

Niall


Also please note that for scenario like above you dont need to use dynamic sql. If it was only for illustration its ok. Anywayts refer link below
http://www.sommarskog.se/dynamic_sql.html
Go to Top of Page
   

- Advertisement -