Please help: Multiple update statements in a script

  • HI,

    Sorry for posting this in wrong thread but I see most members in this thread...I need help...

    I am new to sql server programming. I have to update a table where I have to update different rows with diff data based on primary key. I want to write it in a script instead of multiple update statements updating each row. How can I do that?

    For example:

    update Report_T set Cost_AM = 720.00, Total_Cost_RPS_AM = 830.00, EFFECTIVE_DT=getDate() WHERE SK_SEQ_ID=49

    update Report_T set Cost_AM = 432.00, Total_Cost_RPS_AM = 672.00, EFFECTIVE_DT=getDate() WHERE SK_SEQ_ID=50

    update Report_T set Cost_AM = 360.00, Total_Cost_RPS_AM = 560.00, EFFECTIVE_DT=getDate() WHERE SK_SEQ_ID=51

    update Report_T set Cost_AM = 144.00, Total_Cost_RPS_AM = 224.00, EFFECTIVE_DT=getDate() WHERE SK_SEQ_ID=52

    update Report_T set Cost_AM = 216.00, Total_Cost_RPS_AM = 256.00, EFFECTIVE_DT=getDate() WHERE SK_SEQ_ID=53

    ....

    ....and so on....

    I want to provide this in a script and also role back script with original data just in case if anything goes wrong. can somebody help me out with this. thanks...

  • Triple posted... please click on the user's name to find the other 2.

    This is a huge waste... splits the answers to a single problem into 3 different posts. Please don't cross post.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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