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.

 All Forums
 General SQL Server Forums
 Script Library
 select distinct

Author  Topic 

dominikm86
Starting Member

5 Posts

Posted - 2007-05-16 : 17:06:09
Hi. I am trying to create a view where it will find out the sum of hours for each employee, for each month and year.

SELECT DISTINCT EmpId,
SUM(Hours) AS Hours,
YEAR(WeekStartDate) AS startyear,
MONTH(WeekStartDate) AS startmonth
FROM dbo.BankHours_History
GROUP BY EmpId, WeekStartDate

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-16 : 17:09:44
This sub-forum is not for asking questions.
Didn't you read the descritpion?

SELECT EmpId,
SUM(Hours) AS Hours,
YEAR(WeekStartDate) AS startyear,
MONTH(WeekStartDate) AS startmonth
FROM dbo.BankHours_History
GROUP BY EmpId, YEAR(WeekStartDate), MONTH(WeekStartDate)

SELECT EmpId,
SUM(Hours) AS Hours,
dateadd(month, datediff(month, 0, WeekStartDate), 0) as startmonth
FROM dbo.BankHours_History
GROUP BY EmpId, dateadd(month, datediff(month, 0, WeekStartDate), 0)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

dominikm86
Starting Member

5 Posts

Posted - 2007-05-17 : 08:09:27
thanks
Go to Top of Page
   

- Advertisement -