If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Update tbl SET Case When Condition1 THEN Col1=1 When

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-24-09, 08:55
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
Update tbl SET Case When Condition1 THEN Col1=1 When

I want to do a Update operation to set a new value to Col1. the particular value is dependent on some conditions, Condition1 Condition2.....

I tried a query like the following command, but no luck.

[Code]
Update tbl
SET
Case When
Condition1
THEN Col1=1
When Condition2
THEN Col1=2
END;


I wonder if 'Case When' can only be used in SELECT clauses?

Thanks
Reply With Quote
  #2 (permalink)  
Old 04-24-09, 09:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
UPDATE tbl  
   SET Col1 = CASE WHEN Condition1 
                   THEN 1 
                   ELSE 2 END
 WHERE Condition1 OR Condition2
don't forget the WHERE clause
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On