Results 1 to 2 of 2

Thread: case Statement

  1. #1
    Join Date
    Sep 2002
    Posts
    218

    case Statement

    How do l use the case statement to cater for these updates.


    BEGIN TRANSACTION
    UPDATE TBL_DEV_OL_NEW1
    SET Entity = ('AB')
    WHERE AB_CLIENT = 1
    COMMIT
    GO

    BEGIN TRANSACTION
    UPDATE TBL_DEV_OL_NEW1
    SET Entity = Entity + '' + ' | SB'
    WHERE SB_CLIENT = 1
    COMMIT
    GO

    BEGIN TRANSACTION
    UPDATE TBL_DEV_OL_NEW1
    SET Entity = 'SB'
    WHERE SB_CLIENT = 1 And entity is null
    COMMIT
    go

    BEGIN TRANSACTION
    UPDATE TBL_DEV_OL_NEW1
    SET Entity = Entity + '' + (' | CI')
    WHERE CI_CLIENT = 1
    COMMIT
    GO

    BEGIN TRANSACTION
    UPDATE TBL_DEV_OL_NEW1
    SET Entity = 'CI'
    WHERE CI_CLIENT = 1 And entity is null
    COMMIT
    GO

    BEGIN TRANSACTION
    UPDATE TBL_DEV_OL_NEW1
    SET Entity = Entity + '' + (' | GEMS')
    WHERE GEMS_CLIENT = 1
    COMMIT
    GO

    BEGIN TRANSACTION
    UPDATE TBL_DEV_OL_NEW1
    SET Entity = 'GEMS'
    WHERE GEMS_CLIENT = 1 And entity is null
    COMMIT
    GO

  2. #2
    Join Date
    Sep 2002
    Posts
    12
    Try this:

    UPDATE TBL_DEV_OL_NEW1
    SET Entity = ('AB')
    CASE
    WHEN AB_CLIENT = 1 THEN ('AB')
    WHEN SB_CLIENT = 1 THEN Entity + '' + ' | SB'
    WHEN SB_CLIENT = 1 And entity is null THEN 'SB'
    WHEN ....
    WHEN ...
    ELSE ENTITY
    END

Posting Permissions

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