Problem in procedure

  • Hi,

    I have a procedure which inside I call two other Procedures, the first one is updating table Purchase Order and the second one is updating an intermediary table afterPurchase Order update. I have an issue, the intermediary table is not always being updated. Is there a possibility the transactions for table Purchase Order not have been committed, so when the second procedure is running does not select correctly? Should I use "with(nolock)" in the Purchase Order select ?

    Thank you,

    John

  • With nolock won't help you. Don't think you want to do a dirty read of your data. If you put some code in here we might figure out what the problem is.

  • Did you try using GO?

    Example:

    First SP

    GO

    Second SP


    SELECT quote FROM brain WHERE original = 1
    0 rows returned

  • yb751 (6/15/2015)


    Did you try using GO?

    Example:

    First SP

    GO

    Second SP

    This will not work inside a procedure.

    Can you post your code?

    Michael L John
    If you assassinate a DBA, would you pull a trigger?
    To properly post on a forum:
    http://www.sqlservercentral.com/articles/61537/

  • Michael L John (6/15/2015)


    yb751 (6/15/2015)


    Did you try using GO?

    Example:

    First SP

    GO

    Second SP

    This will not work inside a procedure.

    Can you post your code?

    Darn...missed that in the OP


    SELECT quote FROM brain WHERE original = 1
    0 rows returned

  • j.grimanis (6/15/2015)


    Hi,

    I have a procedure which inside I call two other Procedures, the first one is updating table Purchase Order and the second one is updating an intermediary table afterPurchase Order update. I have an issue, the intermediary table is not always being updated. Is there a possibility the transactions for table Purchase Order not have been committed, so when the second procedure is running does not select correctly? Should I use "with(nolock)" in the Purchase Order select ?

    Thank you,

    John

    SQL statements will run one after the other, they don't overlap, not even when calling different stored procedures. You need to review the code and be sure that it's not a multiple connections problem. Don't use nolock hints, unless you want unreliable results.

    You might want to use explicit transactions to understand what's happenning.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Is there a possibility the transactions for table Purchase Order not have been committed, so when the second procedure is running does not select correctly?

    It's certainly possible, particularly if the code has ROLLBACK statements in it that might be used, such as in a CATCH block.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • The second procedure( which does not work correct some times) is being executed after a "Commit Transaction" inside the first proc. Is there a possibility that rows are still in commit process (multiple users call the first procedure ) and when the second procedure is running, the respective tables have not the updated data? If this happens, how should I solve it...?

  • No, an explicit COMMIT will lock in the transactions.

    But if an explicit BEGIN TRANS was issued and either:

    1) a COMMIT has not yet been issued for that trans

    or

    2) a ROLLBACK has been issued

    then those changes would not be visible to later queries (unless you were using NOLOCK).

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • j.grimanis (6/16/2015)


    The second procedure( which does not work correct some times) is being executed after a "Commit Transaction" inside the first proc. Is there a possibility that rows are still in commit process (multiple users call the first procedure ) and when the second procedure is running, the respective tables have not the updated data? If this happens, how should I solve it...?

    No, that's not a possibility. The second procedure won't start if the first hasn't completed.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Why don't you call the 2nd stored procedure before committing the transaction?

    Are you using in the 2nd stored procedure some identity column values obtained in the first stored procedure? (identity - scope_identity() mistake)

  • j.grimanis (6/15/2015)


    Hi,

    I have a procedure which inside I call two other Procedures, the first one is updating table Purchase Order and the second one is updating an intermediary table afterPurchase Order update. I have an issue, the intermediary table is not always being updated. Is there a possibility the transactions for table Purchase Order not have been committed, so when the second procedure is running does not select correctly? Should I use "with(nolock)" in the Purchase Order select ?

    Thank you,

    John

    Look how many guesses you have, John. How about showing your code so folks don't have to guess?

    โ€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.โ€ - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • ChrisM@Work (6/16/2015)


    j.grimanis (6/15/2015)


    Hi,

    I have a procedure which inside I call two other Procedures, the first one is updating table Purchase Order and the second one is updating an intermediary table afterPurchase Order update. I have an issue, the intermediary table is not always being updated. Is there a possibility the transactions for table Purchase Order not have been committed, so when the second procedure is running does not select correctly? Should I use "with(nolock)" in the Purchase Order select ?

    Thank you,

    John

    Look how many guesses you have, John. How about showing your code so folks don't have to guess?

    That's the bottom line here. Without the code, everything's a guess. We can't see what you see unless you post it.

  • Ed Wagner (6/16/2015)


    ChrisM@Work (6/16/2015)


    j.grimanis (6/15/2015)


    Hi,

    I have a procedure which inside I call two other Procedures, the first one is updating table Purchase Order and the second one is updating an intermediary table afterPurchase Order update. I have an issue, the intermediary table is not always being updated. Is there a possibility the transactions for table Purchase Order not have been committed, so when the second procedure is running does not select correctly? Should I use "with(nolock)" in the Purchase Order select ?

    Thank you,

    John

    Look how many guesses you have, John. How about showing your code so folks don't have to guess?

    That's the bottom line here. Without the code, everything's a guess. We can't see what you see unless you post it.

    Are you saying that you don't have a crystal ball? :w00t: :hehe:

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (6/16/2015)


    Ed Wagner (6/16/2015)


    ChrisM@Work (6/16/2015)


    j.grimanis (6/15/2015)


    Hi,

    I have a procedure which inside I call two other Procedures, the first one is updating table Purchase Order and the second one is updating an intermediary table afterPurchase Order update. I have an issue, the intermediary table is not always being updated. Is there a possibility the transactions for table Purchase Order not have been committed, so when the second procedure is running does not select correctly? Should I use "with(nolock)" in the Purchase Order select ?

    Thank you,

    John

    Look how many guesses you have, John. How about showing your code so folks don't have to guess?

    That's the bottom line here. Without the code, everything's a guess. We can't see what you see unless you post it.

    Are you saying that you don't have a crystal ball? :w00t: :hehe:

    Yes, I shipped it out two weeks ago. ๐Ÿ˜‰

Viewing 15 posts - 1 through 15 (of 22 total)

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