I have three columns - id, programname, status I wanted to use UPDATE with IF condition something like this: UPDATE elec_products IF(programname ='Argos') ( SET status = 1 ) ELSEIF(programname ='sify') ( SET status = 2 ) ELSE ( SET status = 3 ) ENDIF WHERE programname IS NOT NULL Code (markup): I am not sure if it'll be possible. Please suggest the best possible ways to do this. Thank you
Try following. UPDATE elec_products SET STATUS = CASE WHEN programname = 'Argos' THEN 1 WHEN programname = 'sify' THEN 2 ELSE 3 END WHERE programname IS NOT NULL; Code (markup):
Thats great. Thanks a lot. I just made a small change in query: UPDATE elec_products SET stats = CASE programmename WHEN 'Argos' THEN 1 WHEN 'stify' THEN 2 ELSE 3 END CASE WHERE programmename IS NOT NULL Thanks anyway
in a simple way to say take this as an example and try # UPDATE # [account] # SET # balance = # ( # CASE # WHEN # ((balance - 10.00) < 0) # THEN # 0 # ELSE # (balance - 10.00) # END # ) # WHERE # id = 1 and thanks