我创建了一个为用户提供多个选项的参数:
Total Amount = Grand Total
Region 1 = Total Amount for that Region
Region 2 = Total Amount for that Region
Region 3 = Total Amount for that Region
Region 4 = Total Amount for that Region
区域 1 到 4 效果很好,但是当我选择总金额时,我得到的金额不正确。
有人可以告诉我我做错了什么吗?
主要数据集
SELECT OccupancyDetail.CalendarYear, OccupancyDetail.CalendarMonth, SUM(OccupancyDetail.No_of_Nights) AS No_of_Nights,
SUM(OccupancyDetail.Capacity) AS Capacity,Site.BDM,Site.Region
FROM OccupancyDetail INNER JOIN
Site ON OccupancyDetail.Site_Skey = Site.Site_Skey
WHERE (OccupancyDetail.ReferenceDate = convert(Date,getdate()))
AND
CASE WHEN @Time = 'YEAR' THEN CAST(CalendarYear as varchar(4)) else
CalendarMonth + ' ' + CAST(CalendarYear as varchar(4)) end in (@Dates)
GROUP BY OccupancyDetail.ReferenceDate, OccupancyDetail.CalendarYear, OccupancyDetail.CalendarMonth,Site.BDM, Site.Region
Time Dataset
select DateChoice FROM
(select distinct CalendarYear, 1 as MonthNumber,CAST(CalendarYear as varchar(4)) as DateChoice from Time
where @Time = 'YEAR'
union all
select Distinct CalendarYear, MonthNumber,CalendarMonth + ' ' + CAST(CalendarYear as varchar(4)) as DateChoice from Time where @Time = 'MONTH') as QRYDATA
ORDER BY CalendarYear,MonthNumber
BDM 数据集
SELECT DISTINCT BDM
FROM Site