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 > CASE in UPDATE statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-30-06, 03:54
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
CASE in UPDATE statement

Hi,
instread of two updates I would like to write only one update. Is is posible to write update statement using case statement?

Sample:

Code:
Table looks like this:
SELECT * FROM DB2ADMIN.TABLE

A  B
-- ---
00 A01
00 A02
Instread of writting two update statements...
Code:
UPDATE DB2ADMIN.TABLE SET A='01' WHERE A = '00' AND B='A01'
UPDATE DB2ADMIN.TABLE SET A='02' WHERE A = '00' AND B='A02'
... I would like to write one statement:
Code:
UPDATE DB2ADMIN.TABLE SET A =
     CASE
          WHEN A='00' AND B = 'A01' THEN A='01' 
          WHEN A='00' AND B = 'A02' THEN A='02'
          END
I have seen this sample on page SQL Server update - using CASE Expressions. Is this posible on DB2 database?

My system: DB2 v8.2fp9 on Windows XP SP2
Reply With Quote
  #2 (permalink)  
Old 03-30-06, 04:03
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
update Db2admin.table Set A =
Case
When A='00' And B = 'a01' Then '01'
When A='00' And B = 'a02' Then '02'
End
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 03-30-06, 04:25
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
sathyaram_s,
thank you very much it works fine!
Grofaty
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