Thursday, December 26, 2013

Need SQL script to get the 6 months data month wise


select DATEPART(yy, date_of_transaction) [year] , DATEPART(mm,date_of_transaction) [month], COUNT(*) [count]
from mytable
where DATEADD(mm, -6, GETDATE()) <= date_of_transaction
group by DATEPART(yy, date_of_transaction), DATEPART(mm,date_of_transaction)
order by [year], [month]





No comments:

Post a Comment