Используйте, имея
SELECT Count([week]) as 'TotalStarted', [week] FROM
(SELECT
DATEADD(DAY, 2 -DATEPART(WEEKDAY, Crated), CAST(DateStarted as date)) as 'Week'
FROM tableA
WHERE Product like ('1')
AND [DateStarted] >= DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), 0) AND
[DateStarted] <= DATEADD(dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) +1, 0))) tbla
Group by [Week]
HAVING Count([week])>0
Извините, я действительно неправильно понял. Попробуйте что-то вроде этого. На самом деле это ответ avery_larry
Если вы считаете, что вам нужно адаптировать репрезентативный день недели
;WITH [0 to 12] (v) as
(
SELECT V
FROM (
VALUES (0), (1), (2), (3), (4), (5) ,(6), (7), (8), (9), (11), (12)
)T(V)
),
[date_in_qq] (week) as (
SELECT DATEADD(day,DATEDIFF(day,0,DATEADD(qq, DATEDIFF(qq, 0, GETDATE()),0)),v*7)
FROM [0 to 12]
)
SELECT Count(tbla.[week]) as 'TotalStarted', [date_in_qq].[week] FROM
[date_in_qq]
LEFT OUTER JOIN
(SELECT
DATEADD(DAY, 2 -DATEPART(WEEKDAY, Crated), CAST(DateStarted as date)) as 'Week'
FROM tableA
WHERE Product like ('1')
AND [DateStarted] >= DATEADD(qq, DATEDIFF(qq, 0, GETDATE()), 0) AND
[DateStarted] <= DATEADD(dd, -1, DATEADD(qq, DATEDIFF(qq, 0, GETDATE()) +1, 0)))
tbla ON tbla.[week] = [date_in_qq].[week]
Group by [date_in_qq].[Week]