XP-sendmail and "if " statements

  • Good morning,

    I have created a xp_sendmail job to run and I am having the hardest time with the quotes...I tried to create it as a view but it didn't like the if statement. The if statement works fine on its own, so does the xp_sendmail command. Its when I try to combine the two that it gacks. Any thoughts would be appreciated.

    exec master..xp_sendmail

    @recipients = 'lmayer@landmark.edu',

    @query = 'If exists(select * from ChangeStatusVW)

    BEGIN

    PRINT ''The following students have left:''

    PRINT '' ''

    SELECT(last_name + ',' + first_name) as Name

    FROM ChangeStatusVW

    END

    ELSE

    PRINT ''No students have left''',

    @subject ='Test',

    @message ='The contents of the ChangeStatus View',

    @attach results = 'TRUE', @width = 250

    thanks in advance

    Laura

  • I believe the query for xp_sendmail must be a statement(s) that returns a single result set. You are attempting to output messages witht the print statement, whcih is not the same as a result set.

    Steve Jones

    steve@dkranch.net

  • Thanks Steve,

    That would explain it.

    laura

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

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