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
 Distinct?

Author  Topic 

dionismatos
Starting Member

6 Posts

Posted - 2010-03-22 : 15:53:09
Hello All!

I'm having a hard time with the distinct keyword. when i run my query i still get all the values repeated for the same employee. i want do display the name, the code, and the amout of extra hours the employee had in a period of time.

Thanks in advance!

Here is my Query:


select distinct c.empID, c.Nombres, c.apellidos, sum(v.horasextra) as total
from Colaboradores c, ReporteViajes v
WHERE (c.empID = v.empID) and (v.feViaje BETWEEN '2010/03/15' AND '2010/03/31')
GROUP BY c.empID, c.Nombres, c.Apellidos, v.horasextra

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-03-22 : 16:28:06
Remove v.horasextra from the GROUP By clause.
select c.empID, c.Nombres, c.apellidos, sum(v.horasextra) as total 
from Colaboradores c inner join ReporteViajes v on c.empID = v.empID
where v.feViaje BETWEEN '20100315' AND '20100331'
GROUP BY c.empID, c.Nombres, c.Apellidos
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-03-22 : 16:52:44
you can remove the distinct keyword too. not needed in this query
Go to Top of Page
   

- Advertisement -