简体   繁体   中英

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. 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.

From reading online I learned I have to create a dummy param and use VBA code to de-duplicate that list.

So I have these params:

  • param_dummy that gets its available and default values from col1 in the above dataset
  • param that gets a de-duplicate list from param_dummy using 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 .

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. 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
  • a filter where the user can select between the available dropdowns in col1 (de-duplicated)
  • a text filter that allows nulls where a user can filter on 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 .

But this won't work since the query/dataset depends on col1options which gets its default values from the query/dataset.

I can use a second dataset but that means making multiple calls to the SQL server and I want to avoid that.

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)
  3. Add dataset dsParamValues as 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
  5. Add you table/matrix control and set it's dataset property to dsMain

Found an easier solution.

  1. Follow this link to build the "dummy" hidden parameter, the visible paramter and the de-dupe VBA code
  2. Add a tablix properties filter where param is in the visible / non-hidden parameter from above VBA (FYI double click to add parameter)
  3. Adding via double click will append a (0) at the end, remove the (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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