Print Statement in Trigger

  • Please tell me where the results of a print statement can be retrieved when the print statement is executed by a trigger.

    Thx. Jean

  • The bit bucket? I don't think the PRINT statement will actually print any where, but I could be wrong.

  • jean 93062 (9/20/2012)


    Please tell me where the results of a print statement can be retrieved when the print statement is executed by a trigger.

    Thx. Jean

    if you are running a command in SSMS, it will show up in the messages window;

    if you are running an applicaiton, it's probably not available to you unless you did some extra stuff to capture the InfoMessages of the Connection object (i.e. in vb.net AddHandler connection.InfoMessage, New SqlInfoMessageEventHandler(AddressOf OnInfoMessage) on the SqlConnection )

    If you are a programmer,I can giet you an enhanced version of the Microsoft SQLHelper.vb class to expose that, it's pretty easy, but not quite as easy to use;

    I was fiddling around with making an equivilent of the SSMS application so I know how it worked, and it's neat to divert stuff from messages to text to grid.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • I was reading about this and I think the print statement actually does go somewhere. Another developer recommended that the Print statement be used instead of returning a results set.

  • jean 93062 (9/20/2012)


    I was reading about this and I think the print statement actually does go somewhere. Another developer recommended that the Print statement be used instead of returning a results set.

    technically it's available to connections that have an event that is handling the SQLConnection.onInfomessage.

    most connections don't bother; if your developers are using code that does myConn=New SQLConnection(), they are not handling it specifically, so it would be unavailable.

    so if you are not specifically coding fo rit, it's not available...it goes into a null/black hole.

    It's a variation of the tree falling in the woods kind of thing...if you don't put on your ears, you won't hear it.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thank you. I'll consider the issue closed. In this case I did not write the application so I cannot capture the results. I will generate an entry into a log file to track the activity. Appreciate the help.

  • jean 93062 (9/20/2012)


    Thank you. I'll consider the issue closed. In this case I did not write the application so I cannot capture the results. I will generate an entry into a log file to track the activity. Appreciate the help.

    PRINT will not return a result set to the GUI. Only SELECT will.

    BTW, doing either in a trigger is usually a pretty bad idea. The return from the trigger can easily be mistaken by the App as an error being returned.

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

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