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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Creating a variable list of single quoted values

Author  Topic 

MercuryNewt
Starting Member

12 Posts

Posted - 2004-12-29 : 08:58:02
I'm writing a stored procedure with an IF expression that uses NOT IN with a list. I'm trying to create a variable to store the list but I can't seem to come up with a method of single quoting the list that will work in the IF expression. If I create the list within the expression itself like below everything works just fine:

IF CAST(@myVar AS NVARCHAR) NOT IN ('1','2','3') BEGIN PRINT 'It Worked' END

But if I attempt to make my list a variable it won't work, even though the printed output of the list shows it as a comma delimited lits of quoted values:

DECLARE @myQuotedVarList NVARCHAR (50)
SET @myQuotedVarList = '|1|,|2|,|3|'
SET @myQuotedVarList = REPLACE(@myQuotedVarList,'|',CHAR(39))
PRINT @myQuotedVarList
IF CAST(@myVar AS NVARCHAR) NOT IN (@myQuotedVarList) BEGIN PRINT 'It Worked! END ELSE BEGIN 'It Didn't Work!' END

Any assistance would be greatly appreciated!

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-12-29 : 09:01:12
Have a look at the following article:

http://www.sqlteam.com/item.asp?ItemID=11499
Go to Top of Page
   

- Advertisement -