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
 New to SQL Server Programming
 select

Author  Topic 

sureshsmanian
Starting Member

31 Posts

Posted - 2009-10-22 : 11:42:10
hi
I have two tables.
Employee ( Empno - PK, Empname)
LeaveTable (Leavetype, Empno - FK(ref. employee table), no_of_days)


I needed to display the following

Empno Empname Total number of days(total leave)
----- ------- ----------


------- -------- -------

Thanks in advance

Regards
SSM

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-10-22 : 11:44:25
What have you tried so far?
Go to Top of Page

sureshsmanian
Starting Member

31 Posts

Posted - 2009-10-22 : 12:06:43
I have tried this query

Select a.empno, sum(a.no_of_days), b.empname from leavetable a
inner join employee b
on a.empno = b.empno
group by a.empno;

i got the error :
Column 'Employee.EmpName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.


Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-10-22 : 12:48:57
quote:
Originally posted by sureshsmanian

I have tried this query

Select a.empno, sum(a.no_of_days), b.empname from leavetable a
inner join employee b
on a.empno = b.empno
group by a.empno, b.empname

i got the error :
Column 'Employee.EmpName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.


Thanks



modify like below
Go to Top of Page

sureshsmanian
Starting Member

31 Posts

Posted - 2009-10-25 : 04:01:25
Thanks. It is working fine.

Rgds
SSM
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-10-27 : 13:48:38
welcome
Go to Top of Page
   

- Advertisement -