Using dynamic parameter for a IN clause

Banana

split with a cherry atop.
Local time
Today, 03:16
Joined
Sep 1, 2005
Messages
6,318
I'm having an issue forming a stored procedure for SQL Server where I want to use IN() function.

The statement would be something like:
Code:
SELECT a, b FROM foo WHERE a IN ('bar', 'baz');

Hardcoding works, but if I write a SP using a variable:

Code:
SELECT a, b FROM foo WHERE a IN (@var)

and call the variable with input:
Code:
@var = '''bar'', ''baz'''

I get nothing, even though I believe I've escaped the string correctly.

What I could be missing?
 
Figures. :)

I found the answer. It works very well, but not quite so for a partial match.


Any further suggestions or ideas or even comments about performance are welcome.
 

Users who are viewing this thread

Back
Top Bottom