June 10, 2011 at 12:40 am
Hi ,
how to get count of all records on monthly basis.
Eg: i maintain 5 years old data in db..using the below function gives all records for the past 6 months.
DATEADD(MONTH, -6, GETDATE()))
But all i wanted is to get count of all records for each month individually for the latest 6 months.any idea on how to get it??
Expected output
---------------
Name-----code-------Jan--------Feb----Mar-------Apr----May-----Jun
AAA-------111-------1000-------2348---1045------2579----3678---400
June 10, 2011 at 1:05 am
You can use PIVOT to get that kind of results.
Can you provide a table script and some sample data? That would make helping you a lot easier.
-- Gianluca Sartori
June 10, 2011 at 10:48 pm
riys (6/10/2011)
...get count of all records for each month individually [font="Arial Black"]for the latest 6 months[/font].any idea on how to get it??
Yep... Dynamic Cross-Tab. Please see the following article.
http://www.sqlservercentral.com/articles/Crosstab/65048/
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply