Table with added field errormsg
Table1
Name char(50)
clientkey varchar(50)
ErrorMsg varchar(50)
Temp table
Clientkey varchar(50)
ErroMsg varchar(50)
Right now in table1 the ErrorMsg field is null for every Name.
Try the following, it will set the ErrorMsg values in Table1 to be
equal to the ErrorMsg values in the temp table.
UPDATE Table1
SET Table1.ErrorMsg = TempTable.ErrorMsg
WHERE Table1.ClientKey = TempTable.ClientKey
Thanks.
UPDATE Table1
SET ErrorMsg = (SELECT T.ErrorMsg
FROM Temp AS T
WHERE T.clientkey = Table1.clientkey)
WHERE EXISTS(SELECT *
FROM Temp AS T
WHERE T.clientkey = Table1.clientkey);
Or the SQL Server specific update with join (note here that multiple matches on clientkey will result in
non-deterministic update):
UPDATE Table1
SET ErrorMsg = T.ErrorMsg
FROM Table1 AS A
JOIN Temp AS T
ON A.clientkey = T.clientkey;
--
Plamen Ratchev
http://www.SQLStudio.com