我想在SQL查询中实现逻辑
update table
if (column1 = null) then set column1='123'
else set column2 = '123'
答案 0 :(得分:7)
使用条件逻辑,例如:
update t
set column1 = coalesce(column1, '123'),
column2 = (case when column1 is null then column2 else '123' end);
答案 1 :(得分:3)
UPDATE MyTable SET column1 = CASE
WHEN column1 IS Null THEN '123'
ELSE column1
END,
column2 = CASE
WHEN column1 IS Null THEN column2
ELSE '123'
END;