I have to update a large number of rows with the same values, but the values in the update where statement would be different for each row that needs to be updated.
For example col1
and col2
need to be updated to 0
and 1
respectively. This is for all updates.
WHERE col 3 = a, col4 =b and col5 =c
Not managed to do it, apart from using 73 separate update statements.
UPDATE [Mytable].[dbo].[DocumentRegistry]
SET [Document] = 1, [State] = 4
WHERE [col1] = 'abc' AND col2 = 'def' AND col3 = 'ghi' ;
UPDATE [Mytable].[dbo].[DocumentRegistry]
SET [Document] = 1, [State] = 4
WHERE [col1] = '123' AND col2 = '456' AND col3 = '789' ;
UPDATE [Mytable].[dbo].[DocumentRegistry]
SET [Document] = 1, [State] = 4
WHERE [col1] = 'xyz' AND col2 = 'fgh' AND col3 = 'dev';
and so on…….
I get the values for col1, col2, and col3 from this statement:
SELECT r.PNoID, r.DocumentID, r.RegistryID
FROM Documents r WITH(NOLOCK)
INNER JOIN UploadedDocuments d WITH(NOLOCK) ON r.Uniqueid = d.uniqueid
WHERE r.PNoID IN (xxxxxx,xxxxxx,xxxxxxx)
How can I do this?
New contributor
BobJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5