[英]ssrs report report filter with no duplicates used in query
I am having an issue and I'm not sure how to solve it.我遇到了问题,我不知道如何解决。
I have an SSRS report that pulls from a table.我有一个从表格中提取的 SSRS 报告。 I want a parameter filter to show de-duplicated values based on available options in one of the columns.我想要一个参数过滤器根据其中一列中的可用选项显示重复数据删除的值。
So my dataset with a query like:所以我的数据集查询如下:
SELECT * FROM table1 WITH (NOLOCK) WHERE col1 IN (@param)
Then I want a parameter called param
that gets its available and default values from col1
in the above data set and I want them to be de-duplicated.然后我想要一个名为param
,它从上述数据集中的col1
获取其可用和默认值,并且我希望对它们进行重复数据删除。
From reading online I learned I have to create a dummy param and use VBA code to de-duplicate that list.通过在线阅读,我了解到我必须创建一个虚拟参数并使用 VBA 代码去重复该列表。
So I have these params:所以我有这些参数:
param_dummy
that gets its available and default values from col1
in the above dataset param_dummy
从上述数据集中的col1
获取其可用和默认值param
that gets a de-duplicate list from param_dummy
using Code.RemoveDuplicates
param
即会从去重复列表param_dummy
使用Code.RemoveDuplicates
But I'm having an issue with circular logic.但是我在循环逻辑方面遇到了问题。 param
gets its value from param_default
which gets its value from the dataset/query which uses param
. param
从param_default
获取它的值,它从使用param
的数据集/查询获取它的值。
How can I solve this?我该如何解决这个问题?
One thought is to remove the WHERE col1 IN (@param)
and instead use a filter on the Tablix table in the SSRS report.一种想法是删除WHERE col1 IN (@param)
,而是在 SSRS 报告中的 Tablix 表上使用过滤器。 This works but I am wondering how efficient it is.这有效,但我想知道它的效率如何。
And/or if anyone has any other suggestions I am all ears.和/或如果有人有任何其他建议,我全神贯注。
So let us say I have a table in my DB like so:所以让我们说我的数据库中有一个表,如下所示:
| id | col1 | col2 |
|----|------|--------|
| 1 | a | hello |
| 2 | b | how |
| 3 | a | are |
| 4 | c | you |
| 5 | d | on |
| 6 | a | this |
| 7 | b | lovely |
| 8 | c | day |
What I want is:我想要的是:
col1
(de-duplicated)一个过滤器,用户可以在col1
的可用下拉列表之间进行选择(重复数据删除)col2
一个文本过滤器,允许用户可以在col2
过滤的空值So I have a dataset with a query like so:所以我有一个像这样查询的数据集:
SELECT
*
FROM dbo.table1
WHERE col1 IN (@col1options) AND (@col2value IS NULL OR col2 = @col2value)
Then for col1options
I would make available and default options be Get values from a query
and I would use the above dataset and col1
.然后对于col1options
我将提供可用和默认选项是Get values from a query
,我将使用上述数据集和col1
。
But this won't work since the query/dataset depends on col1options
which gets its default values from the query/dataset.但这不起作用,因为查询/数据集取决于col1options
,它从查询/数据集获取其默认值。
I can use a second dataset but that means making multiple calls to the SQL server and I want to avoid that.我可以使用第二个数据集,但这意味着多次调用 SQL 服务器,我想避免这种情况。
I'm not sure I understand your issue so this is a guess... 我不确定我是否理解您的问题,所以这是一个猜测...
If you mean you want to be able to filter your data by choosing one or more entries from a specific column in the table, but this column has duplicates and you want your parameter list to not show duplicates then this is what do to. 如果您是想通过从表中的特定列中选择一个或多个条目来过滤数据,但是此列具有重复项,并且您希望参数列表不显示重复项,则可以这样做。
dsMain
as SELECT * FROM myTable WHERE myColumn IN (@myParam)
将数据集dsMain
添加为SELECT * FROM myTable WHERE myColumn IN (@myParam)
dsParamValues
as SELECT DISTINCT myColumn FROM myTable ORDER BY myColumn
将数据集dsParamValues
添加为SELECT DISTINCT myColumn FROM myTable ORDER BY myColumn
dsParamValues
编辑@myParam参数属性,并将可用值和默认值设置为查询,然后选择dsParamValues
dsMain
添加表/矩阵控件并将其数据集属性设置为dsMain
Found an easier solution.找到了一个更简单的解决方案。
It should work as expected at that point!那时它应该按预期工作! You should be able to select one, some or all parameters and your report should update accordingly.您应该能够选择一个、部分或全部参数,并且您的报告应该相应地更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.