sql server - Using variable in SELECT query inside IN comparison -


here simple example:

why work:

declare @v varchar(75) set @v = 'xxx-xxxx' select * tbl_skus sku = @v 

but not work:

declare @v varchar(75) set @v = 'xxx-xxxx,yyy-yyyy' select * tbl_skus sku in ( @v ) 

both skus 'xxx-xxxx' , 'yyy-yyyy' in table. first query pulls 1 result, , second pulls 0 results; no errors.

because query looking literal 'xxx-xxxx,yyy-yyyy', means it's 1 string, comma in it, not 2 strings separated comma. query translates to:

select * tbl_skus sku in ('xxx-xxxx,yyy-yyyy') 

and work want, shoul be:

select * tbl_skus sku in ('xxx-xxxx','yyy-yyyy') 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -