如何将以下SQL语句简化为1个WHERE
子句:
SELECT *
FROM tabA
WHERE (colCar IS NULL OR colCar = '')
OR (colBike IS NULL OR colBike = '')
OR (colTrain IS NULL OR colTrain = '')
UPDATE tabA
SET Distance = 999
WHERE (colCar IS NULL OR colCar = '') OR
(colBike IS NULL OR colBike = '') OR
(colTrain IS NULL OR colTrain = '')
这句话没有道理,但工作正常。
我只想避免两次使用WHERE
子句。
一些想法?
提前谢谢! 迈克
SQL Server
SELECT *
FROM tabA
WHERE (colCar IS NULL OR colCar = '')
OR (colBike IS NULL OR colBike = '')
OR (colTrain IS NULL OR colTrain = '')
UPDATE tabA
SET Distance = 999
WHERE (colCar IS NULL OR colCar = '')
OR (colBike IS NULL OR colBike = '')
OR (colTrain IS NULL OR colTrain = '')
代码运行正常
答案 0 :(得分:0)
您可以使用OUTPUT子句返回更新的行:
UPDATE tabA
SET Distance = 999
OUTPUT deleted.colCar
, inserted.colCar
, deleted.colBike
, inserted.Distance
WHERE (colCar IS NULL OR colCar = '') OR
(colBike IS NULL OR colBike = '') OR
(colTrain IS NULL OR colTrain = '')