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 |
|
uchacker11
Starting Member
2 Posts |
Posted - 2009-11-20 : 02:58:57
|
| I am trying to write a query that selects the first and last name from the employees table and also displays the sum of hours worked from the hours table and multiplies the sum of the hours by the pay rate. This is what i have so far but i keep getting the following errors:Msg 8120, Level 16, State 1, Line 5Column 'Hours.Hours' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Msg 8120, Level 16, State 1, Line 5Column 'Employees.PayRate' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Select [Employees].[FirstName], [Employees].[Lastname], SUM([Hours].[Hours]) As "TotalHours", ([Hours].[Hours] * [Employees].[PayRate]) As "Pay"from [Hours] inner join [Employees] on [Hours].[EmployeeID] = [Employees].[EmployeeID]Where [Hours].[RebuildID] = '1'Group By [Employees].[FirstName], [Employees].[Lastname] |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-20 : 03:34:10
|
Trysum(([Hours].[Hours] * [Employees].[PayRate])) As Pay No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
uchacker11
Starting Member
2 Posts |
Posted - 2009-11-20 : 03:43:24
|
| Thank you so much i was staring at that for hours! |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-20 : 03:52:52
|
Welcome btw. you can put [Hours].[RebuildID] = '1' into the on-clauseinner join [Employees] on [Hours].[EmployeeID] = [Employees].[EmployeeID] AND [Hours].[RebuildID] = '1'that can speed up your query if there are a lot of entries to join... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|