Comma separated values in a database field

Posted by John Doe on Stack Overflow See other posts from Stack Overflow or by John Doe
Published on 2009-04-10T16:15:50Z Indexed on 2010/05/22 10:20 UTC
Read the original article Hit count: 138

Filed under:
|
|
|

I have a products table. Each row in that table corresponds to a single product and it's identified by a unique Id. Now each product can have multiple "codes" associated with that product. For example:

Id     |    Code
----------------------
0001   |   IN,ON,ME,OH
0002   |   ON,VI,AC,ZO
0003   |   QA,PS,OO,ME

What I'm trying to do is create a stored procedure so that I can pass in a codes like "ON,ME" and have it return every product that contains the "ON" or "ME" code. Since the codes are comma separated, I don't know how I can split those and search them. Is this possible using only TSQL?

Edit: It's a mission critical table. I don't have the authority to change it.

© Stack Overflow or respective owner

Related posts about sql

Related posts about database