; con el pivotdate como (seleccionar el dateadd (semana, 17, “20100101”) como DayInWkNumX)
, keyDates (FirstDayNextWeek, FirstDay9WeeksAgo, FirstDayNextWeekOneYearAgo, FirstDay9WeeksAgoOneYearAgo)
como (
selecto
DATEADD (semana, datediff (semana, 0, DayInWkNumX) +1.0),
DATEADD (semana, datediff (semana, 0, DayInWkNumX) - 9.0),
dateadd (yy, - 1, DATEADD (semana, datediff (semana, 0, DayInWkNumX) +1.0)),
dateadd (yy, - 1, DATEADD (semana, datediff (semana, 0, DayInWkNumX) - 9.0))
de pivotdate
)
seleccionar Weeks10ToToday, Weeks10ToTodayOneYearAgo
de
(SUMA selecta (somevalue) COMO Weeks10ToToday de keyDates
interno ensamblar MyTable
en el >= FirstDay9WeeksAgo del datefield y el datefield < FirstDayNextWeek="">= FirstDay9WeeksAgoOneYearAgo y datefield < FirstDayNextWeekOneYearAgo="">
|