troubleshooting Question

How to use WHERE IN with a list of values from a table

Avatar of gycitsupport
gycitsupport asked on
Microsoft SQL ServerSQL
8 Comments1 Solution255 ViewsLast Modified:
I have a table which contains a list of values, for example :

id      cats
1       2000,2001,2002,2004,2005
2       20010,20011,20014,20015  

What I want is to be able to put the "cats" field into a WHERE IN statement within a stored procedure that I have written in SQL Server 2005.  Unsurprisingly really I get "Conversion failed when converting the varchar value to int" error because WHERE IN takes an int but I need to have a comma delimited list of values ("cats" in the example) to match against.

Any help would be gratefully received!
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros