Table on which query is run我正在对此表执行以下查询:
**What will be the output of this query on the above table:**
UPDATE dsp
SET dsp.HasVersionNumber = CASE
WHEN dsp.ShouldHaveVersionNumber - 1 <= 6 THEN dsp.ShouldHaveVersionNumber
ELSE dsp.ShouldHaveVersionNumber - 1
END
FROM dbo.DeviceProfileStatus dsp
WHERE dsp.ProfileId = 10000003
AND dsp.HasVersionNumber <= 6发布于 2019-08-13 16:36:03
您希望仅当列dsp.ShouldHaveVersionNumber的值为而不是 dsp.ShouldHaveVersionNumber - 1 <= 6时才更新它,因此我认为您的代码应该这样编写:
UPDATE dsp
SET dsp.HasVersionNumber = dsp.ShouldHaveVersionNumber - 1
FROM dbo.DeviceProfileStatus dsp
WHERE dsp.ProfileId = 10000003 AND dsp.HasVersionNumber > 7对于您发布的示例数据,没有任何行将被更新为,因为包含dsp.ProfileId = 10000003的唯一行没有dsp.HasVersionNumber <= 6,它是null。
https://stackoverflow.com/questions/57473947
复制相似问题