Sorry i am not sure how to titled the question well. I want to select few records in sql where a particular column is a set of strings.
Example . I have a table student and has columns ID and name. ID has records 1,2,3,4,5,6 . NAme has A,B,C,D,E,F.
I want to return C,D,E WHERE ID=[3,4,5].
I tried
SELECT FROM student WHERE ID=2,3,4
it gives error, ID=2,3,4 ='2,3,4' and it reads ID as a single columns. I am confused.
Also in my case, ID set are returned in a storedprocedure variable. that is like @ID
SELECT * FROM STUDENT WHERE ID=@ID
@ID above is a variable of a string type holding the set {1,2,3}. Please any help would be appreciated.
WHERE ID=[3,4,5]That's not valid syntax. You wantWHERE ID IN (3, 4, 5), and unfortunately you cannot add a single parameter containing the set of legal values there. Your best option is to either construct the SQL dynamically, or insert the values into a temporary table and do a join (or sub-select in the IN-clause).SELECT FROM student WHERE ID IN (2,3,4)