I’m trying to do an SQL update where I want to set the value of the column being updated depending on the value in a second table. The script below shows what I’m trying to do but so far I haven’t hit on the correct syntax.
update sometable set name =
case
when (select newid from lookuptable where oldid = name) <> null then newid
else name
end
There’s no need for a coalesce or an outer join, because you’re only interested in updating the rows that match.
Also, when comparing a value to null, you should always use
X IS NULLorX IS NOT NULLrather thanX = NULLorX <> NULL, because equality (and inequality) operators always return false for null values.