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
 General SQL Server Forums
 New to SQL Server Programming
 Summing Time Span (for total per hour)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

JGaston
Starting Member

USA
8 Posts

Posted - 09/12/2013 :  13:53:23  Show Profile  Reply with Quote
field prodDate puts out values as such:

8/12/2013 7:50:15
8/12/2013 7:51:03
8/12/2013 7:53:42
8/12/2013 7:54:12
8/12/2013 7:56:02
...
...
8/12/2013 14:57:57
8/12/2013 14:59:59


I'd like to get a time span sum beginning with the first prodDate entry and ending with the last.

The idea is I'll then use that to divide lbs produced, thus giving me a gauge for lb per hour.

-G

James K
Flowing Fount of Yak Knowledge

3706 Posts

Posted - 09/12/2013 :  14:00:05  Show Profile  Reply with Quote
quote:
Originally posted by JGaston

field prodDate puts out values as such:

8/12/2013 7:50:15
8/12/2013 7:51:03
8/12/2013 7:53:42
8/12/2013 7:54:12
8/12/2013 7:56:02
...
...
8/12/2013 14:57:57
8/12/2013 14:59:59


I'd like to get a time span sum beginning with the first prodDate entry and ending with the last.

The idea is I'll then use that to divide lbs produced, thus giving me a gauge for lb per hour.

-G

I didn't quite follow your explanation. Are you trying to add up durations?

Or are you trying to compute the difference between the first prodDate and the lastProdDate, and count how many rows there are within those two times to get an idea of how many rows per hour were produced?
Go to Top of Page

JGaston
Starting Member

USA
8 Posts

Posted - 09/12/2013 :  14:10:13  Show Profile  Reply with Quote
sorry - trying to get the duration between first prodDate and lastProddate.

if first prodDate is 8/12/2013 7:50:15
and last prodDate is 8/12/2013 12:50:15

it would return a value of 5:00:00 or 5 hours.

i want to use that 5 hours to divide another field by(poundsproduced) to get get lbs per hour...
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3706 Posts

Posted - 09/12/2013 :  14:23:12  Show Profile  Reply with Quote
One of these?
-- if PoundsProduced is a known value
DECLARE @PoundsProduced FLOAT;
SET @PoundsProduced = 254.6;
SELECT 
	@PoundsProduced*60.0/NULLIF(datediff(mi,MIN(prodDate),MAX(prodDate)),0) AS PoundsPerHour
FROM YourTable

-- if there is a value for poundsproduced in each row
SELECT 
	SUM(PoundsProduced)*60.0/NULLIF(datediff(mi,MIN(prodDate),MAX(prodDate)),0) AS PoundsPerHour
FROM YourTable
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.05 seconds. Powered By: Snitz Forums 2000