Группировка данных по дням, по месяцам или по годам в MSSQL

По дням:

select convert(char(8),Date_and_Time,112) mydate, count(calls_id)
from calls
group by convert(char(8),Date_and_Time,112)
order by mydate

По месяцам:

select convert(char(6),Date_and_Time,112) mydate, count(calls_id)
from calls
group by convert(char(6),Date_and_Time,112)
order by mydate 

По годам:

select convert(char(4),Date_and_Time,112) mydate, count(calls_id)
from calls
group by convert(char(4),Date_and_Time,112)
order by mydate

MSSQL результат — значения в строку через запятую

Пример запроса:

DECLARE @idName INT
SET @someColumn = 7
DECLARE @s VARCHAR(MAX)
SET @s = ''
SELECT  @s  = @s + CASE WHEN @s <> '' THEN ', ' ELSE '' END + CAST(myColumn AS VARCHAR)
FROM t1
WHERE someColumn = @someColumn
SELECT @s AS ResultList