I have a few tables in my database that I need to update.
Unfortunately, this data has never captured in the past and needs to be done now.
The table I have currently has NULL
in COL2
and COL3
, but they have unique keys in COL1
(obviously).
The basic layout of the tables is like this
ID desc dateCreated wRef tRef
---------------------------------------
T06 url 1/08/2016 NULL NULL
T07 url 1/09/2016 NULL NULL
T04 url 11/10/2016 NULL NULL
The values I'm looking at updating are the wRef
and the tRef
. These values are all unique.
I have been using the below code to update each line. I have this duplicated 1000s of times as there are 1000s of IDs to update.
UPDATE [production].[dbo].[jobsTable]
SET [wRef] = '0004-01', [tRef] = 'T00-07'
WHERE [ID] = 'U19695L'
UPDATE [production].[dbo].[jobsTable]
SET [wRef] = '0005-01', [tRef] = 'T10-04'
WHERE [ID] = 'U16129L'
UPDATE [production].[dbo].[jobsTable]
SET [wRef] = '0010-01', [tRef] = 'T01-06'
WHERE [ID] = 'U17175L'
I'm a SQL newbie - is there an easier or cleaner way to do this?
Thanks in advance.