Very Simple Batch INSERT from IF MATCH

  • well no elgance here what so ever which is a shame.

    I've resolved this by using  'UPDATE' as so:

    UPDATE 'table_1'  set 'column_b' ='lookup value'

    where 'column_a' = 'value'

    30 lines of code to update 1million rows aint bad but I would have liked to have used the 'INSERT' statment along with IF and ELSE.

    IF a = b INSERT x ELSE IF a = c INSERT y

    If anyone can come up with something less clunky I would be intrested to learn. Cheers 

  • din't u try with CASE statements.

    Cheers,
    Sugeshkumar Rajendran
    SQL Server MVP
    http://sugeshkr.blogspot.com

  • You don't tell us what exactly you are trying to do:  insert records from a table, update records base on values.  The solution is probably very similar, but it is easier to respond to something a little more concrete.

    Just to expand on Sugesh's suggestion in an insert scenario.  You would have an insert like:

    Insert into table1

    select x, y, case when column_a = 'value' then 'lookup value' else column_b end

    from table2

    Russel Loski, MCSE Business Intelligence, Data Platform

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

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