Monday, February 3, 2020

How to Create a Report URL for Embedding in an Email

DECLARE @REPORT_URL NVARCHAR(128);

-- REPLACE is doing the URL encoding on date parameters formatted as MM/DD/YYYY
-- assuming report folder name has a space; e.g. REPORT FOLDER
-- assuming report name has a space; e.g. REPORT NAME

SET @REPORT_URL =
CONCAT(
N'http://'
, @SERVER_NAME
, N'/reportserver?%2FREPORT%20FOLDER%2FREPORT%20NAME'
, N'&BeginDate=' 
, REPLACE(FORMAT(@BEGIN_DATE, 'MM/dd/yyyy'), '/', '%2F')
, N'&EndDate=' 
, REPLACE(FORMAT(@END_DATE,   'MM/dd/yyyy'), '/', '%2F')
);

SET @Subject = N'Beneficiary Checks Report: ' + FORMAT(@BEGIN_DATE, 'MM/dd/yyyy') + N' - ' + FORMAT(@END_DATE, 'MM/dd/yyyy')

SET @Body = CONCAT(
N'<div><a href="'
, @REPORT_URL
, N'">Please click this link to view the BLAH BLAH for your branch.</a></div><br><br>'

, N'<div>If you discover any discrepancies or have any questions, please email NAME GOES HERE.<b></div><div>&nbsp</div>'
);