我需要创建一个报告,用户可以切换来自Region>的数据。区>委员会>活动。我使用我无法更改的设置数据视图。我需要定义一个区域和一个区域,因为它们没有在数据库中正确定义,然后将它们相互关联。我已经接近了,因为我能够分配17个不同的“区域代码” - 是的,他们有代码,但没有正确的描述 - 使用CASE语句来组成区域:
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
使用“区域描述”数据我可以创建区:
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
这在SSMS中用于返回查询,但是当我在VS Report Builder中预览报表时,我需要将Region设置为报表的参数。无论我是设置区域的值还是从查询中检索值,我都会在区域预览中获得下拉的1,2,3,4和5(我的区域)的倍数。
我怎样才能让它只返回1,2,3,4或5?有没有办法可以将这些结合起来。如果我使用Distinct然后我会丢失一些数据不是吗?我已尝试使用IN并列出每个分区代码,但返回了相同的问题。
答案 0 :(得分:0)
您的上述代码无法维护。
您应该创建一个区域表来映射您的代码和描述,并加入到该区域表中,并将其用作参数的来源。这将有解决您的问题和改善查询的双重好处