Delay in Print

  • Dear All

    I have procedure A,B,C. Procedure A calls B and C. Procedure B and C have loops and print statement in the loop (for me to understand whats happning). These procedure also have SEELCT (since its under testing phase all these selet and print) before loop.

    But I have noticed that thouch the prints of B are not completly displayed it runs the Procedure C and displays SELECT result of C

    And after some time it displayes remaining prints of B.

    I am not able to understand this behaviour. As per my knowledge everything of B should get over and then only it should start with C.

    Can anybody please explain me the reason of this behaviour

    Regards

  • The print statements are buffered. You won't see them until the buffer is full and the OS (or is it actually SQL Server, not sure) sends them to SSMS.

  • You can use the RAISERROR Statment with the NO WAIT option to achieve the behaviour you want.

  • OTF (6/10/2013)


    You can use the RAISERROR Statment with the NO WAIT option to achieve the behaviour you want.

    You should probably tell the "rest of the story" there. 😉

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

  • Krishna1 (6/9/2013)


    Dear All

    I have procedure A,B,C. Procedure A calls B and C. Procedure B and C have loops and print statement in the loop (for me to understand whats happning). These procedure also have SEELCT (since its under testing phase all these selet and print) before loop.

    But I have noticed that thouch the prints of B are not completly displayed it runs the Procedure C and displays SELECT result of C

    And after some time it displayes remaining prints of B.

    I am not able to understand this behaviour. As per my knowledge everything of B should get over and then only it should start with C.

    Can anybody please explain me the reason of this behaviour

    Regards

    As has been suggested, you can use RAISERROR instead of PRINT statements. There's a catch, though. You have to use a "severity" of 10 or less (preferably just "0" so you know it's a PRINT substitution instead of a real error) and you have to use WITH NOWAIT. The reason for the "severity" of 10 or less is so that it doesn't actually raise an error.

    Here's the simple syntax...

    RAISERROR('Your message here.',0,1) WITH NOWAIT;

    In the above, the "0" is the severity and the "1" is really just a marker (State) which can be assigned just about any number. Most people leave it at 1.

    Now, before you go using it for a "instant" PRINT statement, please go look it up in "Books Online" so that you know of ALL the other wonderful things you can do with this remarkable statement especially when it comes to some of the "printf" options.

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

  • thanks it worked

  • Jeff Moden (6/10/2013)


    OTF (6/10/2013)


    You can use the RAISERROR Statment with the NO WAIT option to achieve the behaviour you want.

    You should probably tell the "rest of the story" there. 😉

    Darn, I was just going to, but someone's gone and done it (better than I would have) 🙂

  • Krishna1 (6/10/2013)


    thanks it worked

    Excellent. Thanks for the feedback.

    --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 8 posts - 1 through 7 (of 7 total)

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