0

I tried using an SQL query below but got an error which says:

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'.

Here's the SQL query

UPDATE TBLGPS 
IF speed >= 0
THEN SET REMARKS = 'Running'
ELSE SET REMARKS = 'Stopped' 
WHERE PLATENO = 'ALCORAN-WIH312' AND TRXTIME = '13:16:20'

Can anyone tell me where I went wrong?

1 Answer 1

3

IF cannot be used in "regular" SQL Statements, use CASE instead:

UPDATE TBLGPS 
   set remarks = case
                    when speed >= 0 then 'Running'
                    else 'Stopped'
                 end
WHERE PLATENO = 'ALCORAN-WIH312' 
AND TRXTIME = '13:16:20'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.