sql ssrs 如何将变量匹配到 table 参数

sql ssrs how to match variable to table parameter

我有一份报告需要一个参数,该参数可能有一个值或一组值(分配给地区办事处的管辖区)。我不知道如何询问 sql 特定值 (a.jurisdiction) 是否与设置为 table 的参数中包含的值匹配。我有以下代码:

DECLARE @District INT = 1614 --Richmond D1
DECLARE @StartDate DATETIME = '20160101'
DECLARE @EndDate DATETIME = '20160731'


DECLARE @Jurisdiction TABLE(Location INT) --= 1223 --Richmond City --multiselect?
IF @District = 1614 --Richmond District 1
INSERT INTO @Jurisdiction Values (1223); --Richmond City
IF @District = 1632 --Newport News District 19
INSERT INTO @Jurisdiction Values (1203); --Newport News
IF @District = 1642 --Fairfax District 29
INSERT INTO @Jurisdiction Values (2568) --Fairfax City
,(1154) ,(1140) ,(1178) ,(1243) 
SELECT b.OffenderId
    , b.Sex
    , b.CurrentLocationId
    , b.MasterTermId
    , b.ReleaseDate
    , b.Jurisdiction
    , b.HomePlanAddress
    FROM (SELECT DISTINCT o.OffenderId
            , o.CurrentLocationId
            , CASE WHEN o.GenderId = 12 THEN 'M'
                WHEN o.GenderId = 13 THEN 'F'
                ELSE 'Unknown' END AS Sex
            , mt.MasterTermId
            , t.TermId 
            , CASE WHEN t.GtrdApprovedDate IS NULL AND
            t.MprdApprovedDate IS NULL THEN '19000101'
        WHEN t.GtrdApprovedDate IS NULL THEN t.MprdApprovedDate
        WHEN t.MprdApprovedDate IS NULL THEN t.GtrdApprovedDate
        WHEN t.MprdApprovedDate < t.GtrdApprovedDate THEN 
                          t.MprdApprovedDate
        ELSE t.GtrdApprovedDate END AS ReleaseDate
        , j.HomePlanAddress
        , j.Jurisdiction    
        FROM ind.Offender AS o
        INNER JOIN (SELECT oa.OffenderId
        , oa.AddressId
        , LTRIM(COALESCE(CAST(a.StreetNumber AS 
                    VARCHAR(10)),' ') + COALESCE(a.StreetNumberSuffix
                    + ' ',' '  
                    + COALESCE(a.StreetName + ',','') + COALESCE(' ' 
                    + a.AppartmentNumber + ',','')
        + l.LocationName + ',' + 'VA ' + COALESCE
                    (a.ZipCode,'')) AS HomePlanAddress
        , j.LocationName AS Jurisdiction
    FROM ind.Offender_Address AS oa
        INNER JOIN ref.Address AS a ON oa.AddressId =
                              a.AddressId
    LEFT JOIN ref.Location AS l ON a.CountyId = l.LocationId
    INNER JOIN ref.Location AS j ON a.JurisdictionId = j.LocationId
    WHERE a.StateId = 1047
    AND EXISTS (SELECT a.JurisdictionId FROM @Jurisdiction)
    --AND a.JurisdictionId IN (@Jurisdiction) --
    AND oa.AddressTypeId = 5 --Proposed
    AND oa.EndDate IS NULL) AS j ON o.OffenderId = j.OffenderId
INNER JOIN scl.MasterTerm AS mt ON o.OffenderId = mt.OffenderId
LEFT JOIN scl.Term AS t ON mt.MasterTermId = t.MasterTermId
WHERE o.CurrentLocationId IS NOT NULL
AND t.TermStatusId <> 631) AS b --Inactive
WHERE b.ReleaseDate BETWEEN @StartDate AND @EndDate

我曾尝试寻找解决方案,但大多数解决方案都涉及使用存储过程,而我无法在我们的环境中使用它。我在找到的一个答案上尝试了 EXISTS 选项,但它给了我所有位置,而不仅仅是参数中的位置。有什么建议吗?

对基于数据集的答案 SSRS 多值参数过滤器的引用似乎没有解决 District 参数与用于 Jurisdiction 的值没有一对一匹配这一事实。但它给了我一些工作和玩耍的机会。

不知道为什么

AND a.JurisdictionId IN (@Jurisdiction)

不适合你。据我所知应该如此。

您可以尝试将 Filter 添加到 SSRS dataset 而不是在查询中。为 Expression 选择 Jurisdiction,并选择 Jurisdiction Parameter 作为 value.