Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Posts
    1,605

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

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    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.

  3. #3
    Join Date
    Jan 2003
    Posts
    1,605
    sathyaram_s,
    thank you very much it works fine!
    Grofaty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •