简体   繁体   English

ssrs 报告过滤器,在查询中没有使用重复项

[英]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 . paramparam_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.和/或如果有人有任何其他建议,我全神贯注。

Updated to add more details...更新以添加更多详细信息...

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:我想要的是:

  • a Tablix to show all the fields from the table一个 Tablix 来显示表中的所有字段
  • a filter where the user can select between the available dropdowns in col1 (de-duplicated)一个过滤器,用户可以在col1的可用下拉列表之间进行选择(重复数据删除)
  • a text filter that allows nulls where a user can filter on col2一个文本过滤器,允许用户可以在col2过滤的空值
  • the parameters will have default values so the table will load on page load参数将具有默认值,因此表格将在页面加载时加载

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. 如果您是想通过从表中的特定列中选择一个或多个条目来过滤数据,但是此列具有重复项,并且您希望参数列表不显示重复项,则可以这样做。

  1. Create a new report 创建一个新报告
  2. Add dataset dsMain as SELECT * FROM myTable WHERE myColumn IN (@myParam) 将数据集dsMain添加为SELECT * FROM myTable WHERE myColumn IN (@myParam)
  3. Add dataset dsParamValues as SELECT DISTINCT myColumn FROM myTable ORDER BY myColumn 将数据集dsParamValues添加为SELECT DISTINCT myColumn FROM myTable ORDER BY myColumn
  4. Edit the @myParam parameter properties and set the available and default values to a query, then choose dsParamValues 编辑@myParam参数属性,并将可用值和默认值设置为查询,然后选择dsParamValues
  5. Add you table/matrix control and set it's dataset property to dsMain 添加表/矩阵控件并将其数据集属性设置为dsMain

Found an easier solution.找到了一个更简单的解决方案。

  1. Follow this link to build the "dummy" hidden parameter, the visible paramter and the de-dupe VBA code按照此链接构建“虚拟”隐藏参数、可见参数和重复数据删除 VBA 代码
  2. Add a tablix properties filter where param is in the visible / non-hidden parameter from above VBA (FYI double click to add parameter)添加Tablix属性过滤器,其中参数可见光/非隐藏参数从上述VBA(FYI双击添加参数)
  3. Adding via double click will append a (0) at the end, remove the (0)通过双击添加将在末尾附加一个(0) ,删除(0)

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.

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