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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Is this query correct?

Author  Topic 

SQLNEWBIZ
Starting Member

27 Posts

Posted - 2013-04-01 : 11:25:05
Hello All,Can anyone please correct the following query,
SELECT e.e_id ,e.fname , Sum (ot.OTHours ) as Tothours,ot.chargesperhour,ot.DateofOT,ot.Payment_Status from employee e inner join OvertimeRecord ot ON ot.E_ID=e.e_id
GROUP BY e.e_id ,e.fname

the error showing is:Column 'OvertimeRecord.ChargesPerHour' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

I am a bit new to these.
Thanks In Advance.

sanjnep
Posting Yak Master

191 Posts

Posted - 2013-04-01 : 11:28:16
Do like this ....

SELECT e.e_id ,e.fname ,ot.chargesperhour,ot.DateofOT,ot.Payment_Status, Sum (ot.OTHours ) as Tothours from employee e inner join
OvertimeRecord ot ON ot.E_ID=e.e_id
GROUP BY e.e_id ,e.fname, ot.chargesperhour,ot.DateofOT,ot.Payment_Status


Sanjeev Shrestha
12/17/1971
Go to Top of Page

SQLNEWBIZ
Starting Member

27 Posts

Posted - 2013-04-01 : 11:33:52
Hello,Sanjeev,
Thankyou..It worked..
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-01 : 13:07:28
those two queries are not equivalent. you'll get completely different resultset when you add those additional columns. Dont know what exactly OP was looking at

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -