简体   繁体   English

SSRS报告参数需要多个值

[英]SSRS report parameter needs multiple values

在此处输入图片说明 I am working on an SSRS report that has a parameter as 'Quarter1', 'Quarter2', 'Quarter3' and 'Quarter4' and I have a query that needs to take the user value and get data for that quarter and my query looks like this if Quarter 1 is selected. 我正在处理一个SSRS报告,该报告的参数为'Quarter1','Quarter2','Quarter3'和'Quarter4',并且我有一个查询,该查询需要获取用户值并获取该季度的数据,而我的查询看起来像如果选择了季度1,则为此。 am using VS 2010 BIDS for SSRS and SQL 2012 for database VS 2010 BIDS用于SSRS,SQL 2012用于数据库

Select 
CASE WHEN MONTH(DateGenerated) <= 3 THEN '1Q/'  
WHEN MONTH(DateGenerated) > 3 and MONTH(DateGenerated) <= 6 THEN '2Q/'
WHEN MONTH(DateGenerated) > 6 and MONTH(DateGenerated) <= 9 THEN '3Q/'
WHEN MONTH(DateGenerated) > 9 and MONTH(DateGenerated) <= 12 THEN '4Q/' END 
as GenDate, Notes, Equation

from SubTask 

 where Year(DateGenerated) = @year and MONTH(DateGenerated) in (@Quarter) 

When doing it in SSRS, I am not able to give months (1, 2 and 3) as value to Quarter1. 在SSRS中执行此操作时,我无法将Quarter(1、2和3)的值提供给Quarter1。 Is there a way that I am missing. 有没有一种我想念的方式。 Appreciate the help.. 感谢帮助。

Your parameter from SSRS will come over as a comma delimited string so we need a function to split the values. 来自SSRS的参数将以逗号分隔的字符串形式出现,因此我们需要一个函数来分割值。

For example, if your parameter is Quarter ... then your SQL would look like 例如,如果您的参数是Quarter ...,则您的SQL看起来像

Create Procedure xyz
@Quarter varchar(50) = null
as BEGIN

Select 
CASE WHEN MONTH(DateGenerated) <= 3 THEN '1Q/'  
WHEN MONTH(DateGenerated) > 3 and MONTH(DateGenerated) <= 6 THEN '2Q/'
WHEN MONTH(DateGenerated) > 6 and MONTH(DateGenerated) <= 9 THEN '3Q/'
WHEN MONTH(DateGenerated) > 9 and MONTH(DateGenerated) <= 12 THEN '4Q/' END 
as GenDate, Notes, Equation

from SubTask 

where Year(DateGenerated) = @year and MONTH(DateGenerated)
 in (Select Value From dbo.FNSplit(@Quarter,','))

And the function is ... 功能是...

CREATE FUNCTION [dbo].[FnSplit]
(
@List nvarchar(max),
@SplitOn nvarchar(5)
)  
RETURNS @RtnValue table 
(

Id int identity(1,1),
Value varchar(max)
) 
AS  
BEGIN
While (Charindex(@SplitOn,@List)>0)
Begin 
Insert Into @RtnValue (value)
Select
Value = ltrim(rtrim(Substring(@List,1,Charindex(@SplitOn,@List)-1))) 
Set @List = Substring(@List,Charindex(@SplitOn,@List)+len(@SplitOn),len(@List))
End 

Insert Into @RtnValue (Value)
Select Value = ltrim(rtrim(@List))
Return
END

GO

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

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