An Idea can change your life.....

Tuesday, September 16, 2008

SQL Server programming Group by day,Month ,Year

--group by day

SELECT COUNT(* ),

Dateadd(DAY,Datediff(DAY,0,HireDate),0) 'day'

FROM Employees

GROUP BY Dateadd(DAY,Datediff(DAY,0,HireDate),0)

ORDER BY Dateadd(DAY,Datediff(DAY,0,HireDate),0) DESC



--group by Month

SELECT COUNT(* ),

Dateadd(MONTH,Datediff(MONTH,0,HireDate),0) 'Month'

FROM Employees

GROUP BY Dateadd(MONTH,Datediff(MONTH,0,HireDate),0)

ORDER BY Dateadd(MONTH,Datediff(MONTH,0,HireDate),0) DESC



No comments: