简体   繁体   English

在Tablix行中显示多值参数的选定值

[英]Display selected values of multi-value parameter in tablix rows

I am designing a report for SSRS. 我正在为SSRS设计报告。 I want the user requesting the report to be able to specify, when they generate the report, from a pre-defined selection some values which should be displayed in a tablix on the report. 我希望请求报告的用户能够在生成报告时从预定义选择中指定一些值,这些值应显示在报告的Tablix中。

I have therefore created a multi-value parameter and populated the Available Values with the options I want the user to be able to select from, and, as expected, when the report is generated the user is able to select one or more of these values. 因此,我创建了一个多值参数,并在“可用值”中填充了我希望用户能够选择的选项,并且,正如预期的那样,在生成报告时,用户能够选择一个或多个这些值。

However, what I now want to do is include a tablix in the report, and display a row for every value in the multi-value parameter that the user selected, with the value displayed in the first cell of the row. 但是,我现在想做的是在报表中包括一个tablix,并为用户选择的多值参数中的每个值显示一行,并在该行的第一个单元格中显示该值。

If the values were coming from a data table this would obviously be easy. 如果这些值来自数据表,这显然很容易。 I've also found answers on how to show all of the selected parameter values in a single textbox using the JOIN function, but I don't want to do that. 我还找到了有关如何使用JOIN函数在单个文本框中显示所有选定参数值的答案,但我不想这样做。

The only solution I can think of is to replicate the list of available values in the multi-value parameter in a tablix manually, and link the visibility of each row of the tablix to the selected state of the corresponding value in the multi-value parameter, but that's not very elegant and increases the effort involved in maintaining the report definition. 我能想到的唯一解决方案是手动复制tablix中多值参数中的可用值列表,并将tablix每行的可见性链接到multi-value参数中相应值的选定状态,但这不是很好,并且会增加维护报告定义的工作量。

Any ideas on how to do this? 有关如何执行此操作的任何想法? I know the selected values from the parameter simply form an array, but I can't see how to bind a tablix to any data that isn't in a dataset, or how to create a dataset from the parameter values. 我知道从参数中选择的值只是形成一个数组,但是我看不到如何将Tablix绑定到数据集中没有的任何数据,或者如何从参数值创建数据集。

Considering that a tablix sources from a dataset, I did some experiments to see how to create a low maintenance solution for you. 考虑到tablix来自数据集,我做了一些实验,看看如何为您创建一个低维护的解决方案。

Option 1 : Create a data set with hard-coded options to match your multi-value parameter and select those options WHERE they exist in the parameter. 选项1 :创建带有硬编码选项的数据集以匹配您的多值参数,并在参数中存在这些选项的情况下选择这些选项。

Example: 例:

 SELECT val
    FROM (
        SELECT 'opt1' as val
        UNION SELECT 'opt2'
        UNION SELECT 'opt3'
        UNION SELECT 'opt4') a
    WHERE val IN (@Param)

Thoughts: easier to maintain than visibility on a table, but still two hard-coded places within the report. 想法:维护比在表上查看要容易,但是报表中仍然有两个硬编码位置。

Option 2 : Create a dataset that selects the multi-value parameter and splits it by each value. 选项2 :创建一个数据集,该数据集选择多值参数并将其按每个值划分。 This was my first idea, but I ran into some issues with determining how to actually select the multi-value without a syntax error. 这是我的第一个想法,但是在确定如何实际选择多值而没有语法错误时遇到了一些问题。 I came up with a method that creates a deliminated string in the report and than parsed that string back into rows in the dataset: 我想出了一种方法,该方法在报表中创建一个限定字符串,然后将该字符串解析回数据集中的行中:

Step 1) Within the dataset properties, on the parameter tab, join the multiple values together with a JOIN expression 步骤1)在数据集属性内的参数选项卡上,将多个值与一个JOIN表达式连接在一起 在此处输入图片说明

Step 2) Create a simple query which uses the new SQL Server 2016 function string_split. 步骤2)创建一个使用新的SQL Server 2016函数string_split的简单查询。 Note that your database compatibility level MUST be 130 or higher to use this function (SQL 2016+). 请注意,您的数据库兼容性级别必须为130或更高才能使用此功能(SQL 2016+)。 If this isn't your scenario, there are many string split functions that you can find on Stack Overflow to achieve the same thing. 如果这不是您的情况,则可以在Stack Overflow上找到许多字符串拆分函数来实现相同的目的。
在此处输入图片说明

Fun problem! 好玩的问题!

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

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