I have a stored procedure..
Proc:
spMyStoredProcedure
Takes a Param:
@List varchar(255)
The @List would be a comma separated list of values i.e... @List = '1,2,3'
(clarity.. a single value of 1 would mean all records with col1 = true)
I have a table with these columns: ID int, col1 bit, col2 bit, col3 bit, col4 bit.
ID | col1 | col2 | col3 | col4
------------------------------
12 | 0 | 1 | 0 | 0
13 | 1 | 0 | 0 | 0
14 | 0 | 0 | 1 | 0
15 | 0 | 0 | 0 | 1
I'd like my result to only include ID's for those rows in the list. i.e. 12,13,14.
My first thought is to loop through the list and do a select. ie. for the first value being 1, I grab all records with a 1 (true) in col1 (resulting in record 12). Then move onto the second value being 2 and grab all records with a 1 (true) in col2 (resulting in record 14) and so on.. I'm wondering if there's a more efficient/better/cleaner way to do this?