Email Step Logs Concatenated

  • Hi,

    I am fairly new to SQL Server, but I wanted to ask a question about step logs and email.

    I have 1 job with 5 steps, because I was tired of getting 5 emails, along with the other 150 I get a day, so I condensed it into one. Each step backs-up a database. I get emailed when the last step completes successfully or if the job fails which there is really no detail in that.

    My question is, is there any way to take the log from each of the 5 steps, concatenate it, and send it by email. It would save a lot of time of digging through the tables of logs.

    I didn't know if this was even possible, but I wanted to ask.

    This is the code I am using to backup a single database as step, just repeated in a different step.

    ---------------------------------------------------------------------------------------------------------------------------------------------------------

    DECLARE @Path NVARCHAR(1000), @FileName NVARCHAR(255), @FullPath NVARCHAR(1255) , @dateString CHAR(8), @dayStr CHAR(2), @monthStr CHAR(2)

    --month variable

    IF (SELECT LEN(CAST(MONTH(GETDATE()) AS CHAR(2))))=2

    SET @monthSTR=CAST(MONTH(GETDATE()) AS CHAR(2))

    ELSE

    SET @monthSTR= '0' + CAST(MONTH(GETDATE()) AS CHAR(2))

    --day variable

    IF (SELECT LEN(CAST(DAY(GETDATE()) AS CHAR(2))))=2

    SET @daySTR=CAST(DAY(GETDATE()) AS CHAR(2))

    ELSE

    SET @daySTR='0' + CAST(DAY(GETDATE()) AS CHAR(2))

    --Assemble Date Format

    SET @dateString=CAST(YEAR(GETDATE()) AS CHAR(4)) + @monthStr + @dayStr

    -- Set Path for Storage

    SET @Path = 'E:\Database_Backups\AMRMVP\'

    --Set Database Name

    SET @FileName = 'AMRMVP_' + @dateString + '.bak'

    SET @FullPath = @Path + @FileName

    --Start Backup of the database

    BACKUP DATABASE AMRMVP

    TO DISK = @FullPath

    WITH INIT

    ---------------------------------------------------------------------------------------------------------

    Any help is greatly appreciated.

    Thanks,

    Mark

Viewing 0 posts

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