COMMIT fixes problem - or will it create one?

  • my client has a stored procedure triggered by shipping action - basically adding an indicator to a shipping file depending on quantities in a shipping table

    if the shipping record quantity is greater than the driver table amount then the indicator gets updated with the driver record quantity and the record is cloned with the remaining quantity minus the indicator

    later records in the driver table don't "see" the records just added

    if I wrap the INSERT statement in a TRANsaction and COMMIT it will it then add the record? and will it update everything processed to this point?

    this is a critical action and I don't want to kill it

  • Probably not, but without seeing the proc and having more details on the process, hard to say.

    Just wrapping something in a transaction is seldom the answer.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • You're doing an INSERT and then want to use the values inserted later within the same query? How about using the OUTPUT clause to capture the values into either variables or a temporary table?

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Grant - that's an interesting solution, which I might just pursue - thanks

    Gail - I am under contract at a client hyper sensitive to intellectual material being stolen - when I posted SQL code that was rewritten (from a suggestion by Mr. Moden) the lawyers made me erase it, even though I renamed anything that could have pointed to the identity of the client - so I am being vague out of necessity

  • Seggerman-675349 (4/2/2015)


    my client has a stored procedure triggered by shipping action - basically adding an indicator to a shipping file depending on quantities in a shipping table

    if the shipping record quantity is greater than the driver table amount then the indicator gets updated with the driver record quantity and the record is cloned with the remaining quantity minus the indicator

    later records in the driver table don't "see" the records just added

    if I wrap the INSERT statement in a TRANsaction and COMMIT it will it then add the record? and will it update everything processed to this point?

    this is a critical action and I don't want to kill it

    Is it absolutely necessary to generate all such intermediate rows for each and every action or can you just generate 1 per batch no matter how many such actions there are?

    --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)

  • the records INSERTed then need to be available to be updated by subsequent records in the driver table - I guess I can say that they are receipt records which need to be applied to order allocation records (except that they aren't) - the receipt records need to be processed in a certain order and the allocation records need to be fulfilled in a certain order as well

    what is happening is that the fulfillment order is not happening in the correct order due to these intermediate records and the web pages the user sees shows odd gaps

Viewing 6 posts - 1 through 5 (of 5 total)

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