如何在 SSRS 中配置多值参数以不传递任何值

How to Configure a Multi-value Parameter in SSRS to also not pass any values

我正在尝试创建一个过滤特定字段的参数,但如果用户不想 select 一个过滤器。 SSRS 报告显示事件的摘要。一些事件有分配给事件的设备,而另一些则没有。 如果我不创建设备参数,报告会显示所有记录:有设备或无设备。在下面的示例中,事件(驱动器 ID)683708、683634、683646)没有分配激励,因此该字段为空。哪个好。

但是当我为设备添加参数时,我被迫创建一个 selection,并且不再显示没有分配设备的事件。我知道为什么会这样,这是有道理的,但我希望有一种方法可以让设备参数允许我 select 'None' 或 'Blank' 或任何措辞查看日期范围内的所有驱动器。

我的程序是这样的:

Create Procedure Hemasphere_IncentiveReport
@startDate datetime,
@endDate datetime,
@RegID varchar(8000),
@OrgID varchar(8000),
@SubID varchar(8000),
@COID varchar(8000),
@EquipmentID varchar(8000)

As

Begin

Select
DM.DriveID [DriveID],
DM.FromDateTime [FromDateTime],
Case When DM.OwnerType = 0 Then Acct.Name Else CD.DescLong End As [OwnerName],
CO.CodeID [CO_ID],
CO.Description [CO_Desc],
Org.CodeID [Org_ID],
Org.Description [Org_Desc],
Sub.CodeID [Sub_ID],
Sub.Description [Sub_Desc],
Reg.CodeID [Reg_ID],
Reg.Description [Reg_Desc],
Inc.Description [Incentive]

From
Hemasphere_Dev.[dbo].rpt_DriveMaster DM
Left Outer Join Hemasphere_Dev.[dbo].rpt_Accounts Acct on DM.AccountID=Acct.AccountID
Inner Join Hemasphere_Dev.[dbo].rpt_CenterDetail CD on DM.CenterID=CD.CenterID
Inner Join Hemasphere_Dev.[dbo].IDViewCollectionOp CO on CD.CenterID=CO.CodeID
Inner Join Hemasphere_Dev.[dbo].IDViewRegion Reg on CD.Region=Reg.CodeID
Inner Join Hemasphere_Dev.[dbo].IDViewOrgCenter Org on CD.OrgCenter=Org.CodeID
Inner Join Hemasphere_Dev.[dbo].IDViewOrgSubCenter Sub on CD.OrgSubCenter=Sub.CodeID
Left Outer Join OBAPPS.[dbo].OBI_Incentives Inc on DM.DriveID=Inc.DriveID

Where
DM.StatusID <>5
And DM.FromDateTime Between @startDate AND @endDate
And CO.CodeID In (Select Number From dbo.fn_SplitInt(@COID,','))
And Inc.EquipmentID In (Select Number from dbo.fn_SplitInt(@EquipmentID,','))

Order By [FromDateTime], [OwnerName], [CO_Desc], [Rec_Desc]

我试过这样的解决方案:

And (Inc.EquipmentID IS NULL or Inc.EquipmentID In (Select Number from dbo.fn_SplitInt(@EquipmentID,',')))

但是当我 select 特定设备时,这会返回空值。关于我可以做些什么来完成这项任务有什么建议吗?

谢谢艾伦,我觉得它快到了,希望你能帮助我扫清最后的障碍。如果我更改我的参数,我会收到此错误:

对于程序本身,您说要使用:

AND (Inc.EquipmentID IN (@EquipmentID) OR (-1 IN (@EquipmentID) AND Inc.EquipmentID IS NULL))

但是我不需要调用函数来拆分整数吗:

And (Inc.EquipmentID In (Select Number From dbo.fnSplitInt(@EquipmentID,',') Or (-1 IN (@EquipmentID) AND Inc.EquipmentID IS NULL))

在设备参数的数据集中,先手动添加一个空白值。

例如:

Select -1 as Value, 'No Equipment' as Label
UNION ALL

Select 此处为您的原始设备数据集

然后在您的报告查询中,而不是:

And (Inc.EquipmentID IS NULL or Inc.EquipmentID In (Select Number from dbo.fn_SplitInt(@EquipmentID,',')))

这样做:

AND (Inc.EquipmentID IN (@EquipmentID)
OR (-1 IN (@EquipmentID) AND Inc.EquipmentID IS NULL))