We help IT Professionals succeed at work.

Sql In Operator, Stored Proc, Array

abhinayp86
abhinayp86 used Ask the Experts™
on
Hi experts,

I have a column status, n i want to pass a comma delimited string to a stored proc(from .net) and use IN operator.

set @sts ='none,edit'

SELECT * FROM table where  [Status] in (@sts))

surely this doesnt work..

Is there any work around??

Thanks,
Abhinay
Declare
@sts nvarchar(max)=null

set @sts ='none,edit'

SELECT * FROM table where  [Status] in (@sts))

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
HI
change to

Declare
@sts nvarchar(max)=null

set @sts =''''none'',''edit'''

set @sts  ='SELECT * FROM table where  [Status] in ('+ @sts +')'

 EXEC sp_executesql @sts