Monday, March 26, 2012

Question on, usage of NOT IN

Hi All,
The following string comparision fails:
declare @.prodCode as nvarchar(50)
select @.prodCode = 'ABZC001'
if @.prodCode NOT IN ( 'ABZC001,CBQA03,FG0023')
BEGIN
...
...
END
The code within the BEGIN...END block is executed!
Any suggestions?
Thanks
kdIN / NOT IN takes a subquery or expression list as an argument. It won't
parse a string for you. I assume this is what you intend:
IF @.prodCode NOT IN ('ABZC001','CBQA03','FG0023')
If you want to search for substrings, use CHARINDEX or PATINDEX.
David Portas
SQL Server MVP
--

No comments:

Post a Comment