Search code examples
sqlsql-serversp-send-dbmail

How to reference parameter values in the email body using sp_send_dbmail


I am trying to include a parameter value in the email body but not sure how to do it. I have declared the parameters and i want to use the SHIFT_START and SHIFT_END in the email body. For example:

declare @Emails   nvarchar (100)
    declare @FullName  nvarchar (100)
    declare @ShiftStart  nvarchar (50)
    declare @ShiftEnd  nvarchar (50)

    DECLARE @EmailBody  VARCHAR(1000)
   set @EmailBody = N'<H1>Hello:</H1>' +
   N'you have indicated that your shift start was "PARAMETER VALUE HERE" and your shift end was "PARAMETER VALUE HERE" ' +
            N'<br>Please make sure.........' +
            N'<br>Thank You' +

Solution

  • You already know how do to this as you're already using the string concatenation (i.e. "+") operator.

    set @EmailBody = N'<H1>Hello:</H1>' +
       N'you have indicated that your shift start was ' + @ShiftStart + ' and your shift end was ' + @ShiftEnd + ' +
                N'<br>Please make sure.........' +
                N'<br>Thank You' +