Referencing TABLE variable in XP_Sendmail

  • Hello,

    I have a Proc in which data is inserted into a table variable called @ResultsTable. Later in the proc if the @@ROWCOUNT of the data in the table is > 0, then I want to do the following:

    EXEC Master.dbo.xp_sendmail

      @recipients ='me@company.com',

      @subject = 'Missing table Data',

      @message = 'The following days are missing from the table:

         ',

      @query = 'SELECT * FROM ' + @ResultsTable

    When I try to run the proc, I get an error indicating that the @ResultsTable is not declared. One problem is that @ResultsTable is declared outside of the EXECUTE statement. Is there any way that I can use the TABLE variable within xp_sendmail to send the results as I'm trying to do here?

    Thank you for your help!

    CSDunn

  • Never mind on this. I went with a global temp table.

    Thanks.

    CSDunn

  • I would recommend not using xp_sendmail and using xpsmtp_send_mail instead. Assuming you are using smtp this is a better solution since you don't have to have outlook loaded on teh machine nor have the client open etc...

    http://www.sqldev.net/xp/xpsmtp.htm

    Cheers,

    Ben


    Cheers,

    Ben Sullins
    bensullins.com
    Beer is my primary key...

Viewing 3 posts - 1 through 2 (of 2 total)

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