SQL - Using an IF ELSE Construct in an UPDATE statement

I'm trying to write a SQL UPDATE statement using an IF ELSE construct and it's not liking my syntax. Is it even possible to use an IF ELSE construct within an UPDATE statment? Here's my code below.


UPDATE T_FORM_PROPERTIES
     IF Order_Seq = 10
        SET Order_Seq = Order_Seq + 3
     ELSE IF Order_Seq = 11
        SET Order_Seq = Order_Seq + 3
     ELSE IF Order_Seq = 12
        SET Order_Seq = Order_Seq + 3
     ELSE
        SET Order_Seq = Order_Seq + 1
     END
 WHERE Form_ID = 31			AND
       Company_Identity_ID = 1	AND
       Order_Seq > 9

Open in new window

BlakeMcKennaAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this should do:
UPDATE T_FORM_PROPERTIES
  SET Order_Seq = CASE 
   WHEN Order_Seq IN ( 10,11, 12) THEN Order_Seq + 3
   ELSE Order_Seq + 1
     END
 WHERE Form_ID = 31                     AND
       Company_Identity_ID = 1  AND
       Order_Seq > 9

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.