I've got an SSRS report with several different drop-down parameter menus, each of which depends on the selections in the menus before them. The report is taking similar data from several different tables, so there is some repeated data, and these values are showing up multiple times in the menus. For example, say I select sites A, B, and C; each of these sites may have warehouses called WH1 and WH3, so "WH1" and "WH3" each show up multiple times in the Warehouse drop-down menu.

I know that the reason it's doing this is because I have both Site name and Warehouse name in my SQL query, and, even though I have the queries for each table joined with a UNION, which should eliminate duplicates, I'm selecting both the Site and Warehouse columns from each table, so each combination of Site and Warehouse is considered a unique value. I can't take the Site column out of the query, because I need to filter the Warehouse menu by Site. Is there a way to get only the unique values of Warehouse for the menu?

Here's my SQL query for the dataset which feeds the Warehouse parameter. The dataset also has a simple filter based on the Site chosen in the first menu.

SELECT DISTINCT Site, Warehouse
FROM T1
UNION
SELECT DISTINCT Site, Warehouse
FROM T2
UNION
SELECT DISTINCT Site, Warehouse
FROM T3
ORDER BY T$CWAR

有帮助吗?

解决方案 2

Here's what ended up working. It's kind of convoluted, and I'll admit that I don't quite understand why it works, but it does work.

SELECT Site, Warehouse, ROW_NUMBER() OVER (PARTITION BY Warehouse
ORDER BY Warehouse) AS RowNum
FROM(
SELECT Site, Warehouse, ROW_NUMBER() OVER (PARTITION BY Warehouse
ORDER BY Warehouse) AS RowNum
FROM Table1) AS T
WHERE T.RowNum = 1

The solution was adapted from the answer to this question: "Invalid column name" error on SQL statement from OpenQuery results

其他提示

Create a new dataset with below query:

select DISTINCT temp.Warehouse from (
SELECT DISTINCT Site, Warehouse
FROM T1
UNION
SELECT DISTINCT Site, Warehouse
FROM T2
UNION
SELECT DISTINCT Site, Warehouse
FROM T3
) temp

Pass this query to availible values in parameter properties of "Warehouse" if needed give in default values also.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top