January 22, 2007 at 8:45 am
I am running into a syntax error when running the follow code:
declare @temp varchar(25)
declare @impstore varchar (10)
declare @sql varchar(1000)
set @temp = 'Store_A'
set @impstore = '18'
exec ('update temp_data set month1_amount = select '
+ @temp + ' from sales where store = ' +@impstore)
The error is Server: Msg 170, Level 15, State 1, Line 8
Line 8: Incorrect syntax near ')'.
I am new at sql server and am plugging along on this. Any help would be great.
January 23, 2007 at 4:06 am
Hi,
The syntax error occurs because you need to put brackets around the select statement that generates the value. Like this,
exec ('update temp_data set month1_amount = (select '
+ @temp + ' from sales where store = ' + @impstore + ')')
Hope that helps,
January 23, 2007 at 6:58 am
Thank you that worked great!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply