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
 Summing values for individuals

Author  Topic 

yidrasil
Starting Member

21 Posts

Posted - 2011-07-07 : 04:26:12
Folks,

I haven't managed to find quite the same request as this after searching sh here goes....

I have a table with columns 'Name' and 'Timeatwork'

The former contains distinct names (no same name cases) the latter values represent hours. I am looking to count hours related to each individual so I may have, for example;

John Smith 10
Simon Jones 3
John Smith 20
Simon Jones 6
Alan James 50

So, looking for an end result of

John Smith 30
Simon Jones 9
Alan James 50

Note that this query runs once daily so will add new names and values on a daily basis. Note also the names are not known in advance.

Have tried summing and grouping but so far unsuccessfully.

Would really appreciate some expert help...

Many thanks,

Yid

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-07-07 : 04:27:34
select name, Timeatwork=sum(Timeatwork)
from tbl
group by name


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

yidrasil
Starting Member

21 Posts

Posted - 2011-07-10 : 17:32:24
Thanks Nigel, just the job. Was over-thinking the issue.

All the best,

Yid
Go to Top of Page
   

- Advertisement -