SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Summing per day rather than per period
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dougancil
Posting Yak Master

USA
217 Posts

Posted - 11/12/2010 :  13:51:54  Show Profile  Send dougancil a Yahoo! Message  Reply with Quote
I am using this query to sum payroll for a time period, but I'd also like to do it per day:

select name, employeenumber, (cast (sum (ontime) as decimal (10,2))) as minutes into scratchpad2
from scratchpad1
where date between '10/1/2010' and '10/15/2010'
group by employeenumber, name
order by employeenumber asc

Would I just use distinct here?

X002548
Not Just a Number

15586 Posts

Posted - 11/12/2010 :  13:54:45  Show Profile  Reply with Quote
what is ontime?

can you post the DDL of the table, sample data and expected results?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 11/15/2010 :  05:47:02  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
select name, employeenumber, dateadd(day,datediff(day,0,date),0) as dateonly,(cast (sum (ontime) as decimal (10,2))) as minutes into scratchpad2
from scratchpad1
where date between '10/1/2010' and '10/15/2010'
group by employeenumber, name ,dateadd(day,datediff(day,0,date),0)
order by employeenumber asc


Madhivanan

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

dougancil
Posting Yak Master

USA
217 Posts

Posted - 11/15/2010 :  10:04:43  Show Profile  Send dougancil a Yahoo! Message  Reply with Quote
Madhivanan,

Thank you. That works perfectly.

Doug
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22761 Posts

Posted - 11/16/2010 :  03:02:56  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by dougancil

Madhivanan,

Thank you. That works perfectly.

Doug


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.15 seconds. Powered By: Snitz Forums 2000