这是我的报告所喜欢的一瞥,一系列图表,您可以选择一个国家和12个月滚动或36个月滚动的日期范围。
该报告在选择一个国家/地区以及在12个月或36个月的日期范围内查看不同数据方面表现良好。
当我'选择所有'国家/地区时出现问题。我想要的是在图表上代表的所有国家的总数。如下所示,选择了所有国家/地区后,图表上的数据与上图无关。
国家/地区参数
这是我的存储过程
ALTER PROCEDURE [name] @Country VARCHAR(max)
,@DateRange VARCHAR(max)
AS
BEGIN
SELECT country
,[yyyy-mm]
,[12Months]
,[36Months]
,[Population]
,[Employed]
FROM (
SELECT CASE [countryID]
WHEN '800002'
THEN 'UK'
WHEN '800003'
THEN 'France'
WHEN '800004'
THEN 'Germany'
ELSE 'N/A'
END AS country
,Convert(CHAR(7), [DateTimeOfCall], 121) "yyyy-mm"
,CASE
WHEN datetimeofcall BETWEEN Dateadd(Month, Datediff(Month, 0, DATEADD(m, - 12, current_timestamp)), 0)
AND Dateadd(Month, Datediff(Month, 0, DATEADD(m, 0, current_timestamp)), 0)
THEN 'y'
ELSE 'n'
END AS [12Months]
,CASE
WHEN datetimeofcall BETWEEN Dateadd(Month, Datediff(Month, 0, DATEADD(m, - 36, current_timestamp)), 0)
AND Dateadd(Month, Datediff(Month, 0, DATEADD(m, 0, current_timestamp)), 0)
THEN 'y'
ELSE 'n'
END AS [36Months]
,sum(CASE
WHEN [CategoryID] = '180003'
AND [CauseID] IN (
'700002'
,'700003'
)
AND [TypeID] = '100002'
AND [PopTypeID] BETWEEN '170002'
AND '170019'
THEN 1
ELSE 0
END) Population
,sum(CASE
WHEN [EmpID] = '210002'
THEN 1
ELSE 0
END) AS Employed
FROM [dbo].[country]
WHERE STATUS = '1'
GROUP BY [countryID]
,Convert(CHAR(7), [DateTimeOfCall], 121)
,CASE
WHEN datetimeofcall BETWEEN Dateadd(Month, Datediff(Month, 0, DATEADD(m, - 12, current_timestamp)), 0)
AND Dateadd(Month, Datediff(Month, 0, DATEADD(m, 0, current_timestamp)), 0)
THEN 'y'
ELSE 'n'
END
,CASE
WHEN datetimeofcall BETWEEN Dateadd(Month, Datediff(Month, 0, DATEADD(m, - 36, current_timestamp)), 0)
AND Dateadd(Month, Datediff(Month, 0, DATEADD(m, 0, current_timestamp)), 0)
THEN 'y'
ELSE 'n'
END
) a
WHERE country in (@country)
AND (
(
@DateRange = 12
AND [12Months] = 'Y'
)
OR (
@DateRange = 36
AND [36Months] = 'Y'
)
)
END
这就是输出
country yyyy-mm Population Employed 12months 36months
uk 2016-06 56 43 y y
france 2016-06 40 22 y y
Germany 2016-06 73 32 y y
uk 2015-06 45 10 n y
france 2015-06 30 11 n y
Germany 2015-06 76 56 n y
AND SO ON......
所有帮助表示感谢,谢谢。