sp_send_dbmail @body containing 2 lines?

Hello am trying to send an email which the body contains 2 lines using the following but am getting error message.

EXEC msdb.dbo.sp_send_dbmail @profile_name='ProfileNameHere',
@recipients = 'RecipientHere@hotmail.com',
@body = 'Line 1 here.' + CHAR(13) + CHAR(10) + 'Line 2 here.',
@subject = 'Subject Here'

Incorrect syntax near '+'.

What am I doing wrong or how can I achieve my 2 lines body email?

Thanks in advance.

July 31st, 2015 5:45pm

EXEC does not accept expressions for the parameters. You need to put the expression in a variable:

DECLARE @body nvarchar(200) =  'Line 1 here.' + CHAR(13) + CHAR(10) + 'Line 2 here.'

EXEC msdb.dbo.sp_send_dbmail @profile_name='ProfileNameHere',
@recipients = 'RecipientHere@hotmail.com',
@body = @body,
@subject = 'Subject Here'

Free Windows Admin Tool Kit Click here and download it now
July 31st, 2015 6:20pm

That did the trick, thanks Erland.
July 31st, 2015 7:07pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics