Update statement

  • i All,

    I want to Update column A1, when column A2 and A3both are NULL or have invalid data.

    If A2 has Valid Data ignore next steps ,if A2 it has NULL or INVALID data check column column A3, IF A3 has NULL or INVALID data update column A1 as BADDATA

    syntax plz

    Please help

  • SQListic (1/21/2014)


    i All,

    I want to Update column A1, when column A2 and A3both are NULL or have invalid data.

    If A2 has Valid Data ignore next steps ,if A2 it has NULL or INVALID data check column column A3, IF A3 has NULL or INVALID data update column A1 as BADDATA

    syntax plz

    Please help

    Do you have datatypes to go with these columns? You have been around here long enough to know we need these kinds of details.

    Something like this:

    Update SomeTable

    set ColumnA = case when A2 has valid data then "something"

    when A2 is null OR "invalid data" then "something else"

    when A3 is null OR "invalid data" then "BADDATA"

    end

    That is best I can piece together from the lack of details posted.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (1/21/2014)


    SQListic (1/21/2014)


    i All,

    I want to Update column A1, when column A2 and A3both are NULL or have invalid data.

    If A2 has Valid Data ignore next steps ,if A2 it has NULL or INVALID data check column column A3, IF A3 has NULL or INVALID data update column A1 as BADDATA

    syntax plz

    Please help

    Do you have datatypes to go with these columns? You have been around here long enough to know we need these kinds of details.

    Something like this:

    Update SomeTable

    set ColumnA = case when A2 has valid data then "something"

    when A2 is null OR "invalid data" then "something else"

    when A3 is null OR "invalid data" then "BADDATA"

    end

    That is best I can piece together from the lack of details posted.

    We should also construct a proper WHERE clause so that only the records that NEED to be updated are actually modified. I see clients modifying ALL rows in a table with frightening regularity!!

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

  • TheSQLGuru (1/21/2014)


    Sean Lange (1/21/2014)


    SQListic (1/21/2014)


    i All,

    I want to Update column A1, when column A2 and A3both are NULL or have invalid data.

    If A2 has Valid Data ignore next steps ,if A2 it has NULL or INVALID data check column column A3, IF A3 has NULL or INVALID data update column A1 as BADDATA

    syntax plz

    Please help

    Do you have datatypes to go with these columns? You have been around here long enough to know we need these kinds of details.

    Something like this:

    Update SomeTable

    set ColumnA = case when A2 has valid data then "something"

    when A2 is null OR "invalid data" then "something else"

    when A3 is null OR "invalid data" then "BADDATA"

    end

    That is best I can piece together from the lack of details posted.

    We should also construct a proper WHERE clause so that only the records that NEED to be updated are actually modified. I see clients modifying ALL rows in a table with frightening regularity!!

    Agreed about a where clause. Of course, there is basically nothing in what I posted that is a proper anything. 😉

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 4 posts - 1 through 3 (of 3 total)

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