有没有办法在报告执行日保留 SSRS 报告的电子邮件订阅参数值?

Is there a way to retain the email subscription parameter values for a SSRS report for the report execution day?

我使用的是标准版 SSRS 2016,因此无法访问数据驱动订阅。我有一个报告订阅,每天 运行 使用固定的 StartDate 参数和 EndDate 参数的默认值,该参数使用表达式将其值设置为今天的日期。

我需要订阅者在报告计划日期过去后重新使用 link,但订阅电子邮件中的 link 仅包含第一个参数值,因此 EndDate 始终使用今天的日期,而不是生成订阅电子邮件的日期。

我想保留报告当天的参数值 运行。有没有办法强制在电子邮件订阅中包含参数值 link?

有什么想法吗?

提前致谢。

您可以创建一个 SQL 服务器作业来发送带有报告的自定义电子邮件 link。

DECLARE @report_url NVARCHAR(500) = ''; --update the report url here
DECLARE @email_body NVARCHAR(MAX) = NULL;

BEGIN
   SET @email_body = '<html><body>Hi,   
   <br><br>
   You can access the report in the link below.
   <br>
   <a href="' + @report_url + '">Your Report</a>
   <br>
   <br>
   </body></html>';

   EXEC [msdb].[dbo].[sp_send_dbmail] 
      @profile_name = 'YourProfileNameHere', 
      @body = @email_body, 
      @body_format = 'HTML', 
      @recipients = 'first.last@yourcompany.com; first.last@yourcompany.com', 
      @blind_copy_recipients = 'first.last@yourcompany.com', 
      @subject = 'Report Email Subject', 
      @query_result_no_padding = 1;
   WAITFOR DELAY '00:00:02';
END;

您可以在报告的页脚中使用参数构建报告url。

=Globals!ReportServerUrl + "/ReportServer?"
+ Replace(Globals!ReportFolder, " ", "+") + "%2f"
+ Replace(Globals!ReportName, " ", "+")
+ "&ReportFolder=" + Join(Parameters!ReportFolder.Value, "&ReportFolder=")
+ "&SearchType=" + Join(Parameters!SearchType.Value, "&SearchType=")
+ IIf(IsNothing(Parameters!SearchFor.Value), "&SearchFor:IsNull=True", "&SearchFor=" + Parameters!SearchFor.Value)
+ IIf(IsNothing(Parameters!CreatedDateFrom.Value), "&CreatedDateFrom:IsNull=True", "&CreatedDateFrom=" + Format(Parameters!CreatedDateFrom.Value, Variables!FormatDate.Value))
+ IIf(IsNothing(Parameters!CreatedDateTo.Value), "&CreatedDateTo:IsNull=True", "&CreatedDateTo=" + Format(Parameters!CreatedDateTo.Value, Variables!FormatDate.Value))
+ IIf(IsNothing(Parameters!ModifiedDateFrom.Value), "&ModifiedDate:IsNull=True", "&ModifiedDateFrom=" + Format(Parameters!ModifiedDateFrom.Value, Variables!FormatDate.Value))
+ IIf(IsNothing(Parameters!ModifiedDateTo.Value), "&ModifiedDateTo:IsNull=True", "&ModifiedDateTo=" + Format(Parameters!ModifiedDateTo.Value, Variables!FormatDate.Value))
+ "&CreatedBy=" + Join(Parameters!CreatedBy.Value, "&CreatedBy=")
+ "&ModifiedBy=" + Join(Parameters!ModifiedBy.Value, "&ModifiedBy=")
+ "&ShowSql=" + CStr(Parameters!ShowSql.Value)
To use Null as a parameter value use: [Parameter Name]:IsNull=True
To use multi value parameters, you must use the Join function
To use boolean values, you must change it to a string e.g. CStr or .ToString()
Name Description
rs:Format Rendering modes you can pass are HTML3.2, HTML4.0, MHTML, IMAGE, EXCEL, WORD, CSV, PDF, XML, defaults to HTML4.0
rc:Zoom Specified in percentages, supports Page%20Width and Whole%20Page, defaults to 100%
rc:Toolbar True/False, used to show/hide the toolbar, defaults to true
rc:Parameters True/False/Collapsed, used to show/hide/collapse the parameters in the toolbar, defaults to true
rc:DocMap True/False, used to show/hide document map, defaults to true (not shown unless report has document map)
rc:Section Specifies default page number to display, defaults to 1
rc:BookMarkID Jumps to a specific bookmark in a report
rc:FindString Provides search criteria to the report and finds the first instance of the string specified