I have a table and want to "copy" the values of column findoc
and insert them in the rows of column findocs
which have null values.
CodePudding user response:
You can use COALESCE()
to take the first non-NULL value:
UPDATE dbo.tablename SET findocs = COALESCE(findocs, findoc);
Though a more efficient way would be to filter:
UPDATE dbo.tablename SET findocs = findoc
WHERE findocs IS NULL AND findoc IS NOT NULL;
CodePudding user response:
You can use coalesce()
in a query:
select coalesce(finddocs, finddoc) sa finddocs, finddoc, sum
from t;
Or to change the values using update
:
update t
set finddocs = finddoc
where finddocs is null;