Update Statement with CASE statement

  • Good day all

    i was tasked to created an UPDATE statement for 6 tables , i would like to update 4 columns within the 6 tables , they all contains the same column names. the table gets its information from the source table, however the data that is transferd to the 6 tables are sometimes incorrect , i need to write a UPDATE statement that will automatically correct the data. the Update statement should also contact a where clause

    the columns are [No] , [Salesperson Code], [Country Code] and [Country Name]

    i was thinking of doing

    Update [tablename]

    SET [No] =

    CASE

    WHEN [No] ='AF01' THEN 'Country Code' = 'ZA7' AND 'Country Name' = 'South Africa'

    ELSE 'Null'

    END

    What is the best way to script this

  • Something along these lines

    UPDATE [tablename]

    SET

    [Country Code] =

    CASE

    WHEN [No] ='AF01' THEN 'ZA7'

    ELSE NULL

    END,

    [Country Name]

    CASE

    WHEN [No] ='AF01' THEN 'South Africa'

    ELSE NULL

    END

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply