I have a table with a field that contains a comma delimited list. The data for the table is input through an HTML form. The comma delimited list is created by checking check boxes on the form.
Eg[tt]
id | name | category
---|------|-----------
1 | bob | 1,10,11,14
2 | ted | 2,11,15
----------------------[/tt]
How do I write an SQL SELECT that will get rows that have a specific number in the comma delimited list? I don't think I can use SELECT * FROM table WHERE category LIKE "%1%" because that would select both bob and ted as the categories both contain 1.
Is there a function I can use that can see the list as distinct numbers delimited by commas, and then select all the ones that contain a specific number (or numbers) in the list? I know how I could do this in JavaScript or ASP, but I would rather SQL Server did the hard work.
I am sure this is a fairly common thing to want to do, but I haven't been able to find anything on the web about it yet. --
Dunx
Eg[tt]
id | name | category
---|------|-----------
1 | bob | 1,10,11,14
2 | ted | 2,11,15
----------------------[/tt]
How do I write an SQL SELECT that will get rows that have a specific number in the comma delimited list? I don't think I can use SELECT * FROM table WHERE category LIKE "%1%" because that would select both bob and ted as the categories both contain 1.
Is there a function I can use that can see the list as distinct numbers delimited by commas, and then select all the ones that contain a specific number (or numbers) in the list? I know how I could do this in JavaScript or ASP, but I would rather SQL Server did the hard work.
I am sure this is a fairly common thing to want to do, but I haven't been able to find anything on the web about it yet. --
Dunx