[英]Can the value of a subscription parameter be set to an expression when creating an SSRS report subscription in SQL Server 2014?
I have a report with two Date parameters "StartDate" and "EndDate." 我有一个带有两个Date参数“ StartDate”和“ EndDate”的报告。
I want to create multiple subscriptions to the report covering different time periods like previous calendar month, previous week, previous weekend, etc. 我想为报告创建多个订阅,涵盖不同的时间段,例如上一个日历月,上一周,上周末等。
The most straightforward way that I can think of doing this is would be if the StartDate and EndDate parameters could be set to different expressions for each subscription. 我想到的最直接的方法是,是否可以为每个订阅将StartDate和EndDate参数设置为不同的表达式。 However I can't seem to get expressions to work at all from the subscription page. 但是,我似乎无法从订阅页面上获取所有表达式。 Is this possible? 这可能吗?
The way I have handled this type of situation was to add a new parameter to the report that would allow you choose a report period to run for. 我处理这种情况的方式是在报告中添加一个新参数,该参数使您可以选择要运行的报告期间。 This value would in turn be used to determine what dates to use for start date and end date. 该值将依次用于确定开始日期和结束日期要使用的日期。
The following steps outline how to do this. 以下步骤概述了如何执行此操作。
Add a new parameter to the report named ReportPeriod
. 将一个新参数添加到名为ReportPeriod
的报表中。
Add the following Label(Value) pairs to the Available Values (Specified values) list. 将以下标签(值)对添加到“可用值(指定值)”列表中。
Make one of these the default, which doesn't matter. 将其中之一设置为默认值,这没关系。
Move this new parameter up in the parameters list so that is above(before) the StartDate
and EndDate
parameters. 在参数列表中将该新参数上移,使其位于StartDate
和EndDate
参数的上方(之前)。 They will derive their values based the chosen ReportPeriod
, so it must come before them. 他们将根据所选的ReportPeriod
导出其值,因此它必须先于它们。
Set the default value expression for the StartDate
parameter to this: 将StartDate
参数的默认值表达式设置为此:
=Switch(Parameters!ReportPeriod.Value = "D", Today.AddDays(-1), Parameters!ReportPeriod.Value = "W", DateAdd(DateInterval.WeekOfYear, -1, DateAdd(DateInterval.Day, -(DatePart(DateInterval.Weekday, Today, 0, 0)-1), Today)), Parameters!ReportPeriod.Value = "M", DateAdd(DateInterval.Month, -1, DateAdd(DateInterval.Day, -(DatePart(DateInterval.Day, Today, 0, 0)-1), Today)))
Set the default value expression for the EndDate
parameter to this: 将EndDate
参数的默认值表达式设置为此:
=Switch(Parameters!ReportPeriod.Value = "D", Today, Parameters!ReportPeriod.Value = "W", DateAdd(DateInterval.Day, -(DatePart(DateInterval.Weekday, Today, 0, 0)), Today), Parameters!ReportPeriod.Value = "M", DateAdd(DateInterval.Day, -(DatePart(DateInterval.Day, Today, 0, 0)), Today))
You need to know that changing the ReportPeriod
when running the report by hand will not update the StartDate
and EndDate
parameters right in front of you eyes. 您需要知道, ReportPeriod
运行报表时更改ReportPeriod
不会更新您眼前的StartDate
和EndDate
参数。 However, changing the default ReportPeriod
will affect the values. 但是,更改默认的ReportPeriod
将影响这些值。 More importantly , what ReportPeriod
you choose when creating a report subscription will also affect the date values. 更重要的是 ,在创建报表订阅时选择的ReportPeriod
也会影响日期值。 Therefore, creating report subscriptions for this report, one for each ReportPeriod
, will give you the results you desire. 因此,为此报表创建报表订阅(每个ReportPeriod
订阅一个)将为您提供所需的结果。
Feel free to add more ReportPeriod
available values, like Quarterly, or Annually, and adjust the expressions as needed. 随时添加更多ReportPeriod
可用值,例如每季度或每年,并根据需要调整表达式。
Hope this helps you. 希望这对您有所帮助。
You can write expressions in SSRS design environment to set a default value for the date. 您可以在SSRS设计环境中编写表达式以设置日期的默认值。 The same will reflect in its subscriptions as "Report Default Value". 在其订阅中也会反映为“报告默认值”。 Custom -configure the date feature using "Override Report Default" is not available even in Data-driven subscriptions in SSRS up to 2012. Users can only select a fixed date. 使用“覆盖默认报表”自定义-配置日期功能即使在2012年之前的SSRS中由数据驱动的订阅中也不可用。用户只能选择一个固定日期。
Maybe this article helps: 也许这篇文章有帮助:
https://www.sqlservercentral.com/Forums/1104266/Creating-a-dynamic-date-parameter-in-a-SQL-Reporting-Services-2005-subscription https://www.sqlservercentral.com/Forums/1104266/Creating-a-dynamic-date-parameter-in-a-SQL-Reporting-Services-2005-subscription
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.