简体   繁体   English

SSRS单个报告参数,用于设置数据集查询参数

[英]SSRS Single report parameter used to set dataset query parameters

I'm a bit of an SSRS noob and would appreciate some assistance with report parameters. 我有点SSRS菜鸟,不胜感激报告参数方面的帮助。

I have a SQL query similar to the following: 我有一个类似于以下内容的SQL查询:

SELECT [abc],[xyz],[etc]
FROM [database].[dbo].[db_view]
WHERE [Date] BETWEEN @StartDate AND @EndDate

Normally this will result in two report parameters being created, [Start Date] and [End Date]. 通常,这将导致创建两个报告参数,即[开始日期]和[结束日期]。 However the default date picker scenario becomes tedious for users when running reports several times for a prior periods and can often select incorrect start and end dates. 但是,默认的日期选择器方案在前几次运行报表时对于用户来说变得很繁琐,并且通常会选择不正确的开始日期和结束日期。

The preferred approach is to provide users with parameters like [Year] and [Month] and have these defaulted to current values, eg: Year:[2014] Month:[March], and use these selections to set the SQL query parameters accordingly, ie the latter selection would be used to set @StartDate='2014/03/01' and @EndDate='2014/03/31' 首选方法是为用户提供[Year]和[Month]之类的参数,并将它们默认为当前值,例如:Year:[2014] Month:[March],并使用这些选择相应地设置SQL查询参数,即后一种选择将用于设置@ StartDate ='2014/03/01'和@ EndDate ='2014/03/31'

I'm not sure how parameters can be set as described above; 我不确定如何如上所述设置参数。 any guidance will be greatly appreciated. 任何指导将不胜感激。

In SSRS, add 2 hidden Parameters, Start and End date. 在SSRS中,添加2个隐藏的参数,开始和结束日期。 Set the defaults of these to an expression. 将这些默认值设置为表达式。 Build out your date strings using the values from your visible year/month parameters, and use CDATE() to convert them to a date type. 使用可见的年/月参数中的值构建日期字符串,然后使用CDATE()将其转换为日期类型。 Use these 2 hidden parameters in your SQL query(s). 在您的SQL查询中使用这2个隐藏参数。

For the year/month parameters, simply add those, navigate to their "Available values" property tab, and either hard-code in your collection of months & years, or wire up a dataset to provide the available values to the parameter. 对于年/月参数,只需添加这些参数,导航到其“可用值”属性选项卡,然后在您的月和年集合中进行硬编码,或连接数据集以为参数提供可用值。

Without parameter expressions (requires SQL Server 2012 data source) 没有参数表达式(需要SQL Server 2012数据源)

  1. In SSRS, ensure separate parameters are created: @Year , @Month , @StartDate , @EndDate 在SSRS中,确保创建了单独的参数: @Year@Month@StartDate@EndDate
  2. Use DATEFROMPARTS to build the start and end dates in your dataset 使用DATEFROMPARTS构建数据集中的开始和结束日期

     SELECT [abc],[xyz],[etc] FROM [database].[dbo].[db_view] WHERE [Date] BETWEEN DATEFROMPARTS(@Year, @Month, @StartDate) AND DATEFROMPARTS(@Year, @Month, @EndDate) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM