Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2007
    Posts
    130

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

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    UPDATE tbl  
       SET Col1 = CASE WHEN Condition1 
                       THEN 1 
                       ELSE 2 END
     WHERE Condition1 OR Condition2
    don't forget the WHERE clause
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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