我尝试使用下面的SQL查询,但收到错误消息:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'IF'.
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'THEN'.
这是SQL查询
UPDATE TBLGPS
IF speed >= 0
THEN SET REMARKS = 'Running'
ELSE SET REMARKS = 'Stopped'
WHERE PLATENO = 'ALCORAN-WIH312' AND TRXTIME = '13:16:20'
谁能告诉我哪里出错了?
答案 0 :(得分:3)
IF
不能用于"常规" SQL语句,改为使用CASE
:
UPDATE TBLGPS
set remarks = case
when speed >= 0 then 'Running'
else 'Stopped'
end
WHERE PLATENO = 'ALCORAN-WIH312'
AND TRXTIME = '13:16:20'