Updating multiple rows using a list of ids
I need to update multiple rows in a table based on IDs. In the stored procedure, I create a varchar variable that contains a list of ids.
Now in the table I have records with IDs 1, 2. The varchar variable has a value 1,2
; so I expect the row to not be updated by the next request.
UPDATE mytbl
SET flag = 1
WHERE Id IN (IdList); -- Here IdList has value '1,2'
But here is the line with Id how is 2
updated. Calling the query also returns the same string. I tried to concatenate IdList
like "'1','2'"
, then it regenerates both rows (with IDs 1 and 2). The data type Id
is int
. Is there a way to store a list of integers?
source to share