Click here to Skip to main content
15,903,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends,
I am trying to write a query where i have to join three tables and to display Employee name and Difference between Sum(Estimated Hours) and Sum(Actual Hours) in a grid.
But on executing the following code , the following Error is shown " Column 'Tasks.Emp_ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause".

SQL
SELECT  
	  
	  Tasks.[Emp_ID],
	  EMPLOYEE.[Emp_Name],
	  Department.[Dept_ID],
	  Department.[Dept_Name],
	  (Sum(Estimated_Hours)-  Sum(Actual_Hours))as Total ,
	  Status_Id
	 	 
	  FROM Tasks   
	  
	  Left Join Employee
	  ON EMPLOYEE.[Emp_ID] = Tasks.[Emp_ID]
	  
	  
	  Left JOIN Department
	  ON EMPLOYEE.Dept_ID = Department.Dept_ID
	  
	  Where Tasks.Status_Id ='1' Or Tasks.Status_Id ='2'
	  Group By Employee.[Emp_Name]	  
    End

someone help me out ...
Thanks in Advance
Posted
Updated 28-Jul-13 21:10pm
v2

1 solution

try this
SQL
select 
Tasks.[Emp_ID],
EMPLOYEE.[Emp_Name],
Department.[Dept_ID],
Department.[Dept_Name],
(Sum(Estimated_Hours)- Sum(Actual_Hours))as Total ,
Status_Id

FROM Tasks 

Left Join Employee
ON EMPLOYEE.[Emp_ID] = Tasks.[Emp_ID]


Left JOIN Department
ON EMPLOYEE.Dept_ID = Department.Dept_ID

Where Tasks.Status_Id ='1' Or Tasks.Status_Id ='2'
Group By Employee.[Emp_Name],Tasks.[Emp_ID],
EMPLOYEE.[Emp_Name],
Department.[Dept_ID],
Department.[Dept_Name],
Status_Id

End
 
Share this answer
 
v2
Comments
MohRizwan 29-Jul-13 5:56am    
Thanks Ashwathi For your Reply... I have solved it Early and your solution is right.Thanks For your reply

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900