首先将您的日历数据转换为可行的格式:
DECLARE @StartDate DATETIME, @EndDate DATETIME
SET @StartDate = '12/01/2018'
SET @EndDate = '01/31/2019'
SELECT @StartDate = DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,@StartDate),0)) -- FirstDayOfMonth
SELECT @EndDate = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@EndDate)+1,0)) -- LastDayOfMonth
; WITH Months AS (
SELECT
[Month] = DATEPART(MONTH,DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,@StartDate),0))),
[Year] = DATEPART(YEAR,DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,@StartDate),0))),
FirstDayOfMonth = DATEADD(s,0,DATEADD(mm, DATEDIFF(m,0,@StartDate),0)),
LastDayOfMonth = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@StartDate)+1,0)),
FirstDayOfCalendar = DATEADD(DAY,-DATEPART(WEEKDAY,DATEADD(s,0,DATEADD(mm,
DATEDIFF(m,0,@StartDate),0)))+1,DATEADD(s,0,DATEADD(mm,
DATEDIFF(m,0,@StartDate),0))),
LastDayOfCalendar = DATEADD(DAY,6-DATEPART(WEEKDAY,DATEADD(s,-1,DATEADD(mm,
DATEDIFF(m,0,@StartDate)+1,0))),DATEADD(s,-1,DATEADD(mm,
DATEDIFF(m,0,@StartDate)+1,0)))
UNION ALL SELECT
[Month] = DATEPART(MONTH,DATEADD(MONTH,1,FirstDayOfMonth)),
[Year] = DATEPART(YEAR,DATEADD(MONTH,1,FirstDayOfMonth)),
FirstDayOfMonth = DATEADD(MONTH,1,FirstDayOfMonth),
LastDayOfMonth = DATEADD(s,-1,DATEADD(mm,
DATEDIFF(m,0,DATEADD(MONTH,1,FirstDayOfMonth))+1,0)),
FirstDayOfCalendar = DATEADD(DAY,-DATEPART(WEEKDAY,DATEADD(MONTH,1,FirstDayOfMonth))+1,DATEADD(MONTH,1,FirstDayOfMonth)),
LastDayOfCalendar = DATEADD(DAY,6-DATEPART(WEEKDAY,DATEADD(s,-1,DATEADD(mm,
DATEDIFF(m,0,DATEADD(MONTH,1,FirstDayOfMonth))+1,0))),DATEADD(s,-1,DATEADD(mm,
DATEDIFF(m,0,DATEADD(MONTH,1,FirstDayOfMonth))+1,0)))
FROM
Months
WHERE
LastDayOfMonth < @EndDate
), Dates AS (
SELECT
[Month],
[Year],
[Date] = FirstDayOfCalendar,
FilterDate = LastDayOfCalendar
FROM
Months
UNION ALL SELECT
[Month],
[Year],
[Date] = DATEADD(DAY,1,[Date]),
FilterDate
FROM
Dates
WHERE
[Date] < FilterDate
)
SELECT
DisplayOnCalendar = DENSE_RANK() OVER (ORDER BY d.Year, d.Month),
d.Month,
[Day] = DATEPART(DAY,d.[Date]),
d.Year,
[WeekDay] = DATEPART(WEEKDAY, d.[Date]),
[Order] = DENSE_RANK() OVER (PARTITION BY d.Year, d.Month ORDER BY d.Date),
d.Date,
case when month(d.Date) = Month then '1' else '2' end as ID
FROM
Dates d
接下来在设计视图中排列您的报告,您需要创建三个矩阵,每个矩阵彼此放置:
较大的矩阵按“=DisplayOnCalender”上的行分组,中等大小的矩阵按“=Ceiling(Fields!Order.Value/7)”上的行分组和“=Weekday”上的列分组。
较小的矩阵包含表达式 =IIF(Fields!ID.Value = 1, Fields!Day.Value, "")
创建两个矩阵后,可以删除深绿色背景行,它们提供相邻字段表达式的信息。将最小的矩阵拖到红色框中。然后将这两个组合矩阵拖到黄色框中。
现在您的报告设计应如右图所示:
我们看到<>,但我们不知道表达式中有什么?