Вопрос

I need to create a report that a user can toggle through data going from Region > District> Committee> Events. I work with set data views that I cannot change. I need to define a District and a Region, as they are not correctly defined in the database and then relate them to each other. I have come close, as I was able to assign the 17 different "DistrictCodes"- Yeah they have the Code, but not the correct descriptions- using a CASE statement to make up the Regions:

CASE WHEN DistrictCode LIKE 'DST10%' THEN 4
WHEN DistrictCode LIKE 'DST13%' THEN 2
WHEN DistrictCode LIKE 'DST1%' THEN 2
WHEN DistrictCode LIKE 'DST2%' THEN 2
WHEN DistrictCode LIKE 'DST3%' THEN 3
WHEN DistrictCode LIKE 'DST5%' THEN 3
WHEN DistrictCode LIKE 'DST7%' THEN 2
WHEN DistrictCode LIKE 'DST8%' THEN 1
WHEN DistrictCode LIKE 'DSTC4%' THEN 3
WHEN DistrictCode LIKE 'DSTC6%' THEN 2
WHEN DistrictCode LIKE 'DSTC9%' THEN 1
WHEN DistrictCode LIKE 'DT11%' THEN 4
WHEN DistrictCode LIKE 'DT12%' THEN 4
WHEN DistrictCode LIKE 'DT15%' THEN 4
WHEN DistrictCode LIKE 'DT16%' THEN 4
WHEN DistrictCode LIKE 'DT17%' THEN 4
WHEN DistrictCode LIKE 'UP17%' THEN 4
WHEN DistrictCode LIKE 'UPL11%' THEN 4
ELSE 5
END AS Region

Using the "District Descriptions" data I could create the District:

CASE WHEN DistrictDesc IN ('1' , '1A' , '1B') THEN 'District 1' 
    WHEN DistrictDesc IN ('2' , '2A' , '2B' , '2C') THEN 'District 2'
    WHEN DistrictDesc IN ('3' , '3A' , '3B') THEN 'District 3'
    WHEN DistrictDesc IN ('4' , '4A' , '4B' , '4C' , '4D' , '4E' , '4F') THEN 'District 4'
    WHEN DistrictDesc IN ('5' , '5A' , '5B' , '5C') THEN 'District 5'
    WHEN DistrictDesc IN ('6' , '6A') THEN 'District 6'
    WHEN DistrictDesc IN ('7' , '7A' , '7B') THEN 'District 7'
    WHEN DistrictDesc IN ('8' , '8A' , '8B' , '8C') THEN 'District 8'
    WHEN DistrictDesc IN ('9' , '9A') THEN 'District 9'
    WHEN DistrictDesc IN ('10' , '10A' , '10B' , '10C') THEN 'District 10'
    WHEN DistrictDesc IN ('11' , '11A' , '11B' , '11C') THEN 'District 11'
    WHEN DistrictDesc IN ('12' , '12A' , '12B' , '12C') THEN 'District 12'
    WHEN DistrictDesc IN ('13' , '13A') THEN 'District 13'
    WHEN DistrictDesc IN ('14' , '14A' , '14B' , '14C' , '14D') THEN 'District 14'
    WHEN DistrictDesc IN ('15' , '15A' , '15B' , '15C' , '15D') THEN 'District 15'
    WHEN DistrictDesc IN ('16' , '16A' , '16B' , '16C') THEN 'District 16'
    WHEN DistrictDesc IN ('17' , '17A' , '17B') THEN 'District 17'
    ELSE ISNULL (DistrictDesc,'No District')
    END AS District

This works in SSMS for returning a query, however when I preview the report in VS Report Builder I need to set Region as a Parameter for the report. Whether I set the values for region or have it retrieve the values from a query, I get multiples of 1, 2, 3, 4, and 5 (my regions) for my drop down in the preview for regions.

How can I get it to return only Once for 1,2,3,4,or 5? is there a way that I Can combine these. If I use Distinct then I would be missing some of the data wouldn't I? I have tried using IN and listing each districtcode, but returned the same issue.

Это было полезно?

Решение

Your code above is not maintainable.

You should create a district table that maps your codes and descriptions, and join to that, and use that as your source for your parameters. This will have the twin benefits of solving your issue, and improving your query

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top