Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have a table that I need to get a count of the records that have entered each month. What is the syntax to do this?select Count(*), max(int_date), min(int_date) from interview group by int_dateThat is what I tried but it didn't give me what I wanted.Thanks,enak
Srinika
Master Smack Fu Yak Hacker
1378 Posts
Posted - 2006-04-13 : 15:29:09
Try the following 2
select Count(*), Datepart(m,int_date) from interview group by Datepart(m,int_date)Order by Datepart(m,int_date)
or
Select A.[Month], A.[Records] from(Select DATENAME ( Month , int_date ) as [Month], Month(int_date) as [No Use], count(*) as [Records] from interview Group by Month(int_date), DATENAME ( Month , int_date ) ) as A Order by A.[No Use]
Srinika
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts
Posted - 2006-04-13 : 17:05:30
[code]select -- First day of month [Interview Month] = dateadd(month,datediff(month,0,int_date),0), [Interview Count] = count(*)from interviewgroup by -- First day of month dateadd(month,datediff(month,0,int_date),0)order by -- First day of month dateadd(month,datediff(month,0,int_date),0)[/code]CODO ERGO SUM
magicmegabytes
Starting Member
1 Post
Posted - 2007-10-21 : 23:08:56
SrinikaThanks for your post. Solutions #1 did it for me. I've been working on this line for 6 hours now.Dave