【问题标题】:Passing multi-value parameter to another parameter将多值参数传递给另一个参数
【发布时间】:2015-04-29 02:55:20
【问题描述】:

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

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

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

但是,将 Department 参数的 Building 查询参数更改为此会使 Department 下拉框显示为禁用。将参数设置为 =Parameters!Building.Value使列表正常工作,但是只有在选择单个建筑物时才出现 - 它是一个空的列表。

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


编辑:详细信息

主报表查询:

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

【问题讨论】:

  • 您在 Department 参数的查询中处理它的方式与在主报表查询或任何其他查询中处理它的方式相同。
  • 听起来应该可以工作。您是否更新了用于 Department 参数的查询以使用 IN 参数!Building.Value?
  • 是的,查询已更新
  • 我已在报告中添加了查询/参数设置的完整详细信息

标签: reporting-services


【解决方案1】:

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

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

this question 中的答案更详细地说明了这一点。

【讨论】:

    猜你喜欢
    • 2014-08-06
    • 2012-09-25
    • 2020-10-03
    • 2018-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多