I'm using the below code to send out an html email using sql server 2012. I'm trying to include the @count inside the html message but can't get it to work. I've tried (' + @count +') as well.
any help would be appreciated
thanks
Code:
Declare @count int = 0
DECLARE @Body NVARCHAR(2000)
SELECT @count = COUNT(1) FROM MY_TABLE
WHERE DATE < GETDATE() -7
AND
STATUS = 'OPEN'
IF @count > 0
BEGIN
SET @Body=N'
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<style>p{font-size:11.0pt;font-family:Calibri,"Arial","serif";}</style>
</head>
<body>
<p>Hello All,</p>
<p><b>This is an automated message</b>,<br />
<br />
You Have '+ @count +' Open Orders</p>
<p>My message</p>
<br />
<p>Thank you<br />
</p>
</body>
</html>'
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'My Porfile',
@recipients = 'MyEmail',
@subject = 'My Subject',
@body = @Body,
@body_format = 'HTML'
END
any help would be appreciated
thanks