Variable using sp_send_dbmail

  • Hello,

    I am working on one script. I am planning to print backup database script using sp_send_dbmail. But , somehow i am getting blank email. Not sure what i am missing.

    Can anyone please help with below code?

    I have attached script for your consideration.

    Thanks all

  • Ok I got a few questions

    EXEC msdb.dbo.sp_send_dbmail

    @recipients = 'xyZ@gmail.com',

    @subject = 'Backup using script',

    @query = @PRINT_BACKUP,

    What's the reason of using @Query instead of @Body

    [ @query = ] 'query'

    Is a query to execute. The results of the query can be attached as a file, or included in the body of the e-mail message. The query is of type nvarchar(max), and can contain any valid Transact-SQL statements. Note that the query is executed in a separate session, so local variables in the script calling sp_send_dbmail are not available to the query.

    Also there is a comma after @PRINT_BACKUP

  • I have implemented using @body. But the problem is that , i am getting multiple emails for each backup script. I need to have all backup scripts within a single email.

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'SQLAlerts',

    @recipients = 'xyz#gmail.com',

    @subject = 'Database backup script',

    @body =@PRINT_BACKUP

    CLOSE db_cursor

    DEALLOCATE db_cursor

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

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