Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Is this query correct?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

SQLNEWBIZ
Starting Member

India
27 Posts

Posted - 04/01/2013 :  11:25:05  Show Profile  Reply with Quote
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

USA
191 Posts

Posted - 04/01/2013 :  11:28:16  Show Profile  Visit sanjnep's Homepage  Reply with Quote
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

India
27 Posts

Posted - 04/01/2013 :  11:33:52  Show Profile  Reply with Quote
Hello,Sanjeev,
Thankyou..It worked..
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 04/01/2013 :  13:07:28  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000