July 21, 2004 at 3:53 pm
Sorry guys, but I have a real simple question that I can't figure out. I'm playing around with this bit of code for now and I can't seem to get it to execute.
DECLARE @filterCriteria varchar
DECLARE @filterCMD varchar
set @filterCriteria = 'w'
IF @filterCriteria LIKE 'W'
set @filterCMD=' DESCRIP LIKE ''%closed%'' or DESCRIP LIKE ''%deny%'' or DESCRIP like ''%withdrawn%'' '
select accountID from TEMP_TABLE WHERE + @filterCMD
SQL Server doesn't like the way I try to concat @filterCMD and says incorrect syntax error. What am I doing wrong?
July 21, 2004 at 5:25 pm
Hey jmarg,
You would have to resort to dynamic SQL to be able to concatenate @filterCMD.
From looking at the code posted, you could do this:
IF @filterCriteria LIKE 'w'
SELECT accountID FROM TEMP_TABLE WHERE DESCRIP LIKE '%closed%' or DESCRIP LIKE '%deny%' or DESCRIP LIKE '%withdrawn%'
JP
July 23, 2004 at 6:53 am
There is no problem with the set statement where @FilterCmd is concatenated. The problem is in the final select statement. The WHERE clause is incorrect.
July 23, 2004 at 7:29 am
Hi,
Try the code given below.
DECLARE @filterCriteria varchar
DECLARE @filterCMD varchar
declare @sql1 nvarchar(200)
set @filterCriteria = 'w'
IF @filterCriteria LIKE 'W'
set @filterCMD=' DESCRIP LIKE ''%closed%'' or DESCRIP LIKE ''%deny%'' or DESCRIP like ''%withdrawn%'' '
set @sql1='select accountID from TEMP_TABLE WHERE ' + @filterCMD
exec sp_executesql @sql1
Hope this solves the issue.
Nivedita Sundar.N
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply