4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 MYSQL - How to use UPDATE with IF-ELSE condition
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
jeffrey78
Junior WebHelper
Junior WebHelper


Joined: 04 Nov 2010
Posts: 2

PostPosted: Thu Nov 25, 2010 6:55 am (13 years, 4 months ago) Reply with QuoteBack to Top

I have three columns - id, programname, status

I wanted to use UPDATE with IF condition something like this:


Code:
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



I am not sure if it'll be possible. Please suggest the best possible ways to do this.
Thank you
OfflineView User's ProfileFind all posts by jeffrey78Send Personal MessageVisit Poster's Website
gmybft
Junior WebHelper
Junior WebHelper


Joined: 30 Nov 2010
Posts: 1

PostPosted: Tue Nov 30, 2010 2:16 am (13 years, 4 months ago) Reply with QuoteBack to Top

Try following.

Code:
UPDATE elec_products
SET STATUS = CASE
WHEN programname = 'Argos' THEN
   1
WHEN programname = 'sify' THEN
   2
ELSE
   3
END
WHERE programname IS NOT NULL;
OfflineView User's ProfileFind all posts by gmybftSend Personal MessageVisit Poster's Website
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.198196 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme