将多值参数传递给另一个参数

Passing multi-value parameter to another parameter

我有一个包含 2 个参数的报告 - 下拉 select 建筑物 (@buildings) 和部门 (@departments) 的离子。当建筑物被 selected 时,部门列表仅限于该建筑物内的部门。

当报表参数没有设置为single-selection时,这很简单-部门的查询参数设置为@building,所以上面的工作。

不过,新的要求是能够多select建筑。我修改了我的后台查询以使用 Building in (@building) 而不是 @building = Building 并将主报告的 Building 查询参数更改为 =String.Join(Parameters!Building.Value, ",") 所以一切都正确通过。

但是,将 Department 参数的 Building 查询参数更改为此会使 Department 下拉框显示为禁用。将参数设置为 =Parameters!Building.Value 会使列表起作用,但只有当单个建筑物被 selected 时 - 它显示为一个空列表。

如何设置一个参数以多值参数作为参数?


编辑:完整细节

主报表查询:

create proc dbo.GetReport (
    @buildings varchar(max), @departments varchar(max)) as
select <columns>
from dbo.MainReport
where Building in (@buildings) and Department in (@departments)

主要报表参数设置:

@buildings: =Join(Parameters!Buildings.Value, ",")
@departments: =Join(Parameters!Departments.Value, ",")

建筑参数查询:

create proc dbo.GetBuildings as
select <columns> from dbo.Buildings

部门参数查询:

create proc dbo.GetDepartments(
    @buildings varchar(max))
select <columns> from dbo.Departments 
where Building in (@buildings)

部门参数设置:

// This will make the Departments drop-down disabled
@buildings: =Join(Parameters!Buildings.Value, ",")
// So will this
@buildings: =Split(Join(Parameters!Buildings.Value, ","), ",")
// This will only work when only one building is selected
@buildings: =Parameters!Buildings.Value

您不能以这种方式(使用 IN() 子句)在存储过程中处理来自 SSRS 的多值参数。该方法仅在您在 SSRS 中生成 SQL 查询时有效(不调用存储过程)。

要在存储过程中使用多值参数,您必须对存储过程中的参数调用拆分函数,并加入它以获取结果。

this question 中的答案更加详细。