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 2000 Forums
 Transact-SQL (2000)
 Sum using distinct

Author  Topic 

dougancil
Posting Yak Master

217 Posts

Posted - 2010-11-03 : 17:48:35
I am trying to do a sum for distinct names in a table using the following query:

select name, employeenumber, ontime1, sum (ontime1) as totalminutes
from scratchpad1
where date between '5/1/2010' and '5/15/2010'
group by name, employeenumber, ontime1

and what I get back is as follows:

Cametria Alexander 8451 .000000000 .000000000
Cametria Alexander 8451 3.349950000 3.349950000
Cametria Alexander 8451 3.447833333 3.447833333


What I'm trying to do is to sum all the ontime1 entries for each day per name. What's the best way to do this?

Thank you

Doug

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-11-03 : 17:53:30
[code]select name, employeenumber, ontime1, sum (ontime1) as totalminutes
from scratchpad1
where date between '5/1/2010' and '5/15/2010'
group by
name, employeenumber, ontime1
[/code]
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-11-04 : 04:07:14
And delete the last comma too.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-11-04 : 05:52:09
Also make sure to use unambigious date formats
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

dougancil
Posting Yak Master

217 Posts

Posted - 2010-11-04 : 10:50:04
Thank you very much. That was it.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-11-04 : 14:15:18
Glad to help!
Go to Top of Page
   

- Advertisement -