I am trying to make this automated with a loop where I define an beginning and ending time period @t_begin , @t_end starting from 0 to 24 for example. CURRENTLY, I am putting all these codes one by one, and for ending t=60 for example, I need to copy and paste 60 subqueries.
The thing matters below is tMONTHS=0,1,2,...... I dont want to copy them all the way to t=24 for example.
SELECT
(
SELECT COUNT(CODE) FROM #TEMP
WHERE (tMONTHS = 0) AND (KANALKODU = @channel) AND (tSTATUS = 2) AND (TARIH < @datelimit)
) as T,
(
SELECT COUNT(CODE) FROM #TEMP
WHERE (tMONTHS = 1) AND (KANALKODU = @channel) AND (tSTATUS = 2) AND (TARIH < @datelimit)
) as t1,
(
SELECT COUNT(CODE) FROM #TEMP
WHERE (tMONTHS = 2) AND (KANALKODU = @channel) AND (tSTATUS = 2) AND (TARIH < @datelimit)
) as t2,
(
SELECT COUNT(CODE) FROM #TEMP
WHERE (tMONTHS = 3) AND (KANALKODU = @channel) AND (tSTATUS = 2) AND (TARIH < @datelimit)
) as t3;
GO