我有一个SSRS报告,它有10个参数,用户希望从参数中看到'ALL'值作为默认值。每个参数都有一个包含100个值的列表,将所有参数作为默认值传递,从而影响性能。如何添加一个“全部”值,报告将其解释为所有选项的含义?我是SSRS的初学者,所以请原谅我。我尝试了几个选项,但无法使报告正常工作。
报告由sp驱动,并具有相应的数据集来驱动参数。 sp有2个ctes从不同来源提取数据,最后它在2个ctes之间有一个联合,以显示两个来源提供的所有数据。
在where子句中,我使用的是一个split函数,当我传递多个源时它会分裂。我明确提到'ALL'参数。 这是我到目前为止所做的一个示例
Create procedure dbo.Testreport
@BusinessUnit varhar(max),
@State varchar(max),
@Class varchar(max),
@StartDate date,
@EndDate date,
@Source varchar(10)
AS begin
;with ABC
As
( Select CustomerName, CustID, Address,
StateName,Business,ClassCode,EffectiveDate,ExpirationDate,Source='FDM'
From table A),
XYZ AS
( Select CustomerName, CustID, Address,
StateName,Business,ClassCode,EffectiveDate,ExpirationDate,Source='MAS'
From table B),
ReportingData As
( Select * from ABC
UNION
Select * from XYZ) select * from ReportingData
where Source in(select * from dbo.fnsplit(@Source))
and @BusinessUnit = 'ALL' or Business=@BusinessUnit
and @State ='ALL' or State=@State
and @Class='ALL'or ClassCode=@Class
and EffectiveDate>=@StartDate and ExpirationDate<=@EndDate
END
在2012年报告构建器中,对于参数数据集,我正在做类似的事情 数据集BusinessUnit
;with BU
As (Select BUID,BusinessUnit from table A
union
Select BUID, BusinessUnit from table B)
select '-1' as BUID, 'ALL' as BusinessUnit
UNION
select '1' as BUID, BusinessUnit From BU
然后在@BuisnessUnit参数中,我使用'ALL'来设置默认值Tab。 当我在报表生成器中运行报表时,在预览窗格中我看不到任何数据。设计可能有什么问题?
任何指针都会非常感激!
感谢。
答案 0 :(得分:0)
您尚未向我们展示的代码部分可能存在其他问题,但您需要解决的一件事是在where子句中使用括号。
而不是:
where Source in(select * from dbo.fnsplit(@Source))
and @BusinessUnit = 'ALL' or Business=@BusinessUnit
and @State ='ALL' or State=@State
and @Class='ALL'or ClassCode=@Class
and EffectiveDate>=@StartDate and ExpirationDate<=@EndDate
你需要这个:
where Source in(select * from dbo.fnsplit(@Source))
and (@BusinessUnit = 'ALL' or Business=@BusinessUnit)
and (@State ='ALL' or State=@State)
and (@Class='ALL'or ClassCode=@Class)
and EffectiveDate>=@StartDate
and ExpirationDate<=@EndDate