Re: Dynamic String !

Re: Dynamic String !

 

  


Usman,

You were close. If you try:

Declare @ABC VARCHAR(10)
set @ABC = 'Oye'
EXEC ('SELECT' + ' '' UPDATE ' + @ABC + '''' )

It should work. You had extra quotes around @ABC and you had closed the quotes after the update.

It can get confusing when doing this type of work. You may want to consider doing it using an intermediate variable to store the string to be executed. That way, you can look at the string to see if it is syntactically correct.

(Something like:)

Declare @ABC VARCHAR(10)
Declare @DEF VARCHAR(1000)
set @ABC = 'Oye'
set @DEF = 'SELECT' + ' '' UPDATE ' + @ABC + ''''
print @DEF
EXEC (@DEF )

. . . Tom

Tom Zeblisky





-----------------------------------------------------------------
Visit our Internet site at http://www.reuters.com

Any views expressed in this message are those of the individual
sender, except where the sender specifically states them to be
the views of Reuters Ltd.
MS Sql Server LazyDBA home page