Comma separated values in a database field
- by John Doe
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.