T-SQL Print Command help please

  • I found this in the SQL books online. Print command returns a user message to the client. So I create a very simple trigger for table CustomerBudget in SQL server:

    Create trigger [test] on customerBudget

    for insert

    as

    begin

              print "This is a test"

    end

    Then I go to MS access, do an ODBC link to the table, insert one record to the linked table but I didn't see the message: "This is a test".

    I wonder if anybody can help me with this print command or other ways to display a message to client in a trigger. Thank you

  • I think you're getting your PRINT output, but Access is losing it for you.

    You could create a work table and instead of using PRINT, use an INSERT into that work table with the message you want to see.

  • The PRINT command will work if you're in Query Analyzer, but it is a message and not part of the data results.  Access isn't expecting extra messages, and I'm not even sure where you think it would be displayed.

    I don't know why you're using Access as an interface to SQL Server for testing, but stop doing it.  We'll forgive you this time.

  • Try this, instead...

    SELECT "This is a test"

     

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

  • ..except you'd want to change the double quotes to single...

    SELECT 'This is a test'







    **ASCII stupid question, get a stupid ANSI !!!**

  • THAT's what I get for being in a hurry!  Thanks, Sushila...

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

  • anytime jeff!

    seeing as how you always get everything right (hurry or not) this was probably a one-time catch!







    **ASCII stupid question, get a stupid ANSI !!!**

  • Now, I'm blushing But I haven't caught you yet and that's even better

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

  • it's no consolation jeff - remi'll tell you (& i'll spare him the trouble of saying so) that it's only a matter of time!







    **ASCII stupid question, get a stupid ANSI !!!**

  • It's also a matter of missed opportunities .

  • ah - ever the perfect gentleman! thx. remi!







    **ASCII stupid question, get a stupid ANSI !!!**

  • I like to be accurate .

  • Thank you for all your help. I will try the Select 'This is a test' statement.

  • Using SELECT inside a trigger may work, but it is a worse crime against nature than using Access as your front end for this kind of development & testing.  You still haven't given any reason for not using Query Analyzer (where the PRINT will work).

    From BOL:

    Returning Results

    It is recommended that a trigger not return any results. This is because special handling for these returned results must be written into every application in which modifications to the trigger table are allowed. To prevent any results from being returned from a trigger, do not include either SELECT statements or variable assignments in the definition of the trigger. If variable assignment must occur in a trigger, use a SET NOCOUNT statement at the beginning of the trigger to eliminate the return of any result sets.

  • Basically, this is what I want. I have an SQL server database and a Visual Foxpro application connecting to it. I can't change any code in the Visual Foxpro application (front end ). We bought it as a package. So I wonder if I can create triggers to send some message to the client when people insert a Sales order or do something else.

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

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