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.
| Author |
Topic |
|
markie88
Starting Member
3 Posts |
Posted - 2012-01-13 : 21:30:30
|
| Hi all,I need help constructing a query that returns the number of days an employee works in May as well as the number of days they work in June in two separate columns for comparison.I can easily get one to show the number of days in May and June in 2 separate queries, but need help getting into one.I have this for the days in may:Select name, Count(*) as Days_in_MayFrom tblHours, tblEmpWhere tblhours.empId=tblEmp.empID AND date >='2010-05-01' AND date <='2010-05-31'Group By nameThis givesName Days_in_MayBob 18Larry 22and so on...Any help is appreciated! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-14 : 00:16:39
|
| [code]Select name,DATEPART(mm,dateadd(mm,datediff(mm,0,[date]),0)) as monthval, Count(*) as Days_in_MayFrom tblHours, tblEmpWhere tblhours.empId=tblEmp.empID Group By name,DATEPART(mm,dateadd(mm,datediff(mm,0,[date]),0))[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|