我有一份基于地理位置的SSRS报告。数据集返回项目记录,包括区域区域,选区和城市级别。我创建了从区域到选举再到城市的级联参数。
但是,每个项目可以选择一个选区内的多个城市。用户请求仅选择该城市的参数过滤器 记录。因此,如果选择的参数是:
如果他们选择仅" Cranbrook",他们只需要选择仅 Cranbrook的项目记录,而不是选择Cranbrook和Rockyview的项目。
现在,我的报告结果将显示选择了Cranbrook的所有记录以及在项目中选择的其他城市。例如,我会看到选择了Cranbrook的所有项目以及选择了Cranbrook和Rockyview的所有项目。
以下是我的报告的更多细节。
@Regional
- 区域数据集中的可用值(选择所有可用的)@Area
- 选区数据集中的可用值(选择@Regional中的所有选项)@City
- 来自City Dataset的可用值(选择@area中的所有值)@Status
- 所有可用状态@Fiscal Year
- 所有可用的财政年度。我在我的详细信息数据集查询(下方)上有一个过滤器,它只过滤了@city
参数中的那些城市。
我的数据集查询:
SELECT Filteredcbt_geographicarea.cbt_electoralareaidname
, Filteredcbt_geographicarea.cbt_name AS City
, Filteredcbt_project.cbt_projectnumber
, Filteredcbt_geographicarea.cbt_electoralidname
, Filteredcbt_projectfiscalyear.cbt_committedamount
, Filteredcbt_projectfiscalyear.cbt_commitmentavailable
, Filteredcbt_projectfiscalyear.cbt_commitmentdisbursed
, Filteredcbt_project.cbt_organizationlegalnameidname
, Filteredcbt_project.statuscodename
, Filteredcbt_projectfiscalyear.cbt_projectnameid
, Filteredcbt_projectfiscalyear.cbt_programfiscalyearidname
, Filteredcbt_projectfiscalyear.cbt_fiscalyearidname
, Filteredcbt_regionaldistrict.cbt_name AS [Regional District]
FROM Filteredcbt_regionaldistrict
INNER JOIN Filteredcbt_electoralarea ON Filteredcbt_regionaldistrict.cbt_regionaldistrictid = Filteredcbt_electoralarea.cbt_regionaldistrictid
INNER JOIN Filteredcbt_category
INNER JOIN Filteredcbt_program ON Filteredcbt_category.cbt_categoryid = Filteredcbt_program.cbt_categoryid
INNER JOIN Filteredcbt_project ON Filteredcbt_program.cbt_programid = Filteredcbt_project.cbt_programnameid
INNER JOIN Filteredcbt_projectfiscalyear ON Filteredcbt_project.cbt_projectid = Filteredcbt_projectfiscalyear.cbt_projectnameid
INNER JOIN Filteredcbt_cbt_project_cbt_geographicarea ON Filteredcbt_project.cbt_projectid = Filteredcbt_cbt_project_cbt_geographicarea.cbt_projectid
INNER JOIN Filteredcbt_geographicarea ON Filteredcbt_cbt_project_cbt_geographicarea.cbt_geographicareaid = Filteredcbt_geographicarea.cbt_geographicareaid
ON Filteredcbt_electoralarea.cbt_electoralareaid = Filteredcbt_geographicarea.cbt_electoralareaid
WHERE (Filteredcbt_geographicarea.cbt_electoralareaidname IN (@Area)) AND (Filteredcbt_project.statuscodename IN (@Status)) AND
(Filteredcbt_projectfiscalyear.cbt_fiscalyearidname IN (@FiscalYear)) AND (Filteredcbt_regionaldistrict.cbt_name IN (@Regional)) AND
(Filteredcbt_geographicarea.cbt_name IN (@City)) AND (NOT EXISTS
(SELECT cbt_electoralareaid, cbt_electoralareaidname, cbt_electoralid, cbt_electoralidname, cbt_geographicareaid, cbt_name
FROM Filteredcbt_geographicarea AS ga1
WHERE (cbt_name NOT IN (@City)) AND (cbt_geographicareaid = Filteredcbt_cbt_project_cbt_geographicarea.cbt_geographicareaid)))
ORDER BY Filteredcbt_projectfiscalyear.cbt_fiscalyearidname
ORDER BY Filteredcbt_projectfiscalyear.cbt_fiscalyearidname;
Filteredcbt_cbt_project_cbt_geographicarea示例:
cbt_cbt_project_cbt_geographicareaid cbt_geographicareaid cbt_projectid
A6D7292F-EA05-E411-BCEA-00155D0470B9 4EB4F611-4BD1-E311-8AB9-00155D067193 2C2FC521-EA05-E411
998F9FE5-2806-E411-BCEA-00155D0470B9 38B4F611-4BD1-E311-8AB9-00155D067193 54FD66DD-2806-E411-
9A8F9FE5-2806-E411-BCEA-00155D0470B9 7EB4F611-4BD1-E311-8AB9-00155D067193 54FD66DD-2806-E411-
956F0BD1-2A06-E411-BCEA-00155D0470B9 5BB4F611-4BD1-E311-8AB9-00155D067193 82B478C7-2A06-E411-
54D3ED7F-2C06-E411-BCEA-00155D0470B9 54B4F611-4BD1-E311-8AB9-00155D067193 ADC83877-2C06-E411-
55D3ED7F-2C06-E411-BCEA-00155D0470B9 C8B4F611-4BD1-E311-8AB9-00155D067193 ADC83877-2C06-E411-
EBDC3544-2E06-E411-BCEA-00155D0470B9 5BB4F611-4BD1-E311-8AB9-00155D067193 40C1163C-2E06-E411-
70A9B479-AE06-E411-BCEA-00155D0470B9 54B4F611-4BD1-E311-8AB9-00155D067193 F24BE26E-AE06-E411-
616C21B3-B506-E411-BCEA-00155D0470B9 65B4F611-4BD1-E311-8AB9-00155D067193 C4389EAA-B506-E411-BCEA-
626C21B3-B506-E411-BCEA-00155D0470B9 99B4F611-4BD1-E311-8AB9-00155D067193 C4389EAA-B506-E411-BCEA-
636C21B3-B506-E411-BCEA-00155D0470B9 ABB4F611-4BD1-E311-8AB9-00155D067193 C4389EAA-B506-E411-BCEA-
646C21B3-B506-E411-BCEA-00155D0470B9 F7B4F611-4BD1-E311-8AB9-00155D067193 C4389EAA-B506-E411-BCEA-

Filteredcbt_geographicarea样本:
cbt_electoralareaid cbt_electoralareaidname cbt_geographicareaid cbt_name
16B4F611-4BD1-E311-8AB9-00155D067193 Town of Creston 2EB4F611-4BD1-E311-8AB9-00155D067193 Alice Siding
13B4F611-4BD1-E311-8AB9-00155D067193 RDCK Area I 2FB4F611-4BD1-E311-8AB9-00155D067193 Thrums
0EB4F611-4BD1-E311-8AB9-00155D067193 RDCK Area D 30B4F611-4BD1-E311-8AB9-00155D067193 Ainsworth Hot Springs
0EB4F611-4BD1-E311-8AB9-00155D067193 RDCK Area D 31B4F611-4BD1-E311-8AB9-00155D067193 Argenta

谢谢,如果您需要任何其他信息,请与我们联系。
答案 0 :(得分:0)
尝试将此添加到WHERE子句中:
AND NOT EXISTS(
SELECT * FROM Filteredcbt_geographicarea ga1
WHERE ga1.cbt_name NOT IN (@City)
AND ga1.cbt_geographicareaid=Filteredcbt_cbt_project_cbt_geographicarea.cbt_geographicareaid
)
如果有效,我会在答案中加上解释。 :)
答案 1 :(得分:0)
如果您使用
添加另一个表到您的联接INNER JOIN (SELECT Filteredcbt_geographicarea.cbt_geographicareaid, string_agg(Filteredcbt_geographicarea.cbt_name, ', ') AS City_List
FROM Filteredcbt_geographicarea
GROUP BY 1) City_List_Lookup ON City_List_Lookup.cbt_geographicareaid = Filteredcbt_cbt_project_cbt_geographicarea.cbt_geographicareaid
使用此表,您可以将连接的城市与输入的参数进行比较。
所以你的where子句变成了:
City_List_Lookup.City_List = (@City)
通过将各个城市连接在一起,您可以查找整个列表仅包含一个城市的情况。