View Full Version : Using dynamic parameter for a IN clause


Banana
11-24-2008, 12:46 PM
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:
SELECT a, b FROM foo WHERE a IN ('bar', 'baz');

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

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

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

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

What I could be missing?

Banana
11-24-2008, 01:02 PM
Figures. :)

I found the answer (http://www.amorsley.net/bugsplat/archives/000623.html). It works very well, but not quite so for a partial match.


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