是否可以将此查询合并到一个UPDATE语句中?
UPDATE [dbo].[MyTable]
SET Column1 = Column2
UPDATE [dbo].[MyTable]
SET Column3 = 1
WHERE Column1 IS NOT NULL
感谢。
答案 0 :(得分:3)
UPDATE [DBO].[MyTable]
SET Column1 = Column2,
Column3 = (
CASE
WHEN Column1 IS NOT NULL
THEN 1
ELSE Column3
END)
答案 1 :(得分:1)
这应该适合你:
UPDATE [dbo].[MyTable]
SET Column1 = Column2
,Column3 =
case
when Column1 IS NOT NULL THEN 1
else Column3
end