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 > DB2 > how can i update this within a single statement?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-29-09, 22:45
laknar laknar is offline
Registered User
 
Join Date: Jul 2008
Posts: 80
how can i update this within a single statement?

how to update a table based on multiple single column values.

IF COLUMN1='P' THEN update stats COLUMN2 AS 'W' Else update COLUMN2 AS 'S';

how can i update this within a single statement?
Reply With Quote
  #2 (permalink)  
Old 03-29-09, 23:37
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Quote:
..... based on multiple single column values.
I couldn't understand well this clause.

Quote:
IF COLUMN1='P' THEN update stats COLUMN2 AS 'W' Else update COLUMN2 AS 'S';
This would be the following statement.
Code:
UPDATE .....
   SET column2
       = CASE column1
         WHEN 'P' THEN
              'W'
         ELSE 'S'
         END
 WHERE .....
;
Reply With Quote
  #3 (permalink)  
Old 03-30-09, 00:06
laknar laknar is offline
Registered User
 
Join Date: Jul 2008
Posts: 80
many thanks it worked for me.
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