By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,124 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,124 IT Pros & Developers. It's quick & easy.

Calculating consecutive Date/Time records

P: n/a
I have a query that returns the results of a process. The start time
for Step 2 is the End Time for step 1. I need to know how long each
step takes.

My current query

Product Step
24324201-05 Step1 7/31/2007 12:11:53 AM
24324201-05 Step2 7/31/2007 12:12:00 AM
24324201-05 Step3 7/31/2007 12:12:21 AM

Aug 13 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Aug 13, 3:32 pm, turtle <kol...@vistacontrols.comwrote:
I have a query that returns the results of a process. The start time
for Step 2 is the End Time for step 1. I need to know how long each
step takes.

My current query

Product Step
24324201-05 Step1 7/31/2007 12:11:53 AM
24324201-05 Step2 7/31/2007 12:12:00 AM
24324201-05 Step3 7/31/2007 12:12:21 AM
What i want to do is calculate the difference from step 1 to step 2 on
the first record and then the dif between step 2 and step 3 on the 2nd
record.
thanks
KO

Aug 13 '07 #2

P: n/a
select A.product, 'Step' & count(*) as StepNbr, A.step
from
(
select product, step
from products
) as A
inner join
(
select product, step
from products
) as B
on A.product = B.product
and A.Step >= B.Step
group by A.product, A.step

turtle wrote:
I have a query that returns the results of a process. The start time
for Step 2 is the End Time for step 1. I need to know how long each
step takes.

My current query

Product Step
24324201-05 Step1 7/31/2007 12:11:53 AM
24324201-05 Step2 7/31/2007 12:12:00 AM
24324201-05 Step3 7/31/2007 12:12:21 AM
Aug 14 '07 #3

P: n/a
or:

select A.product, 'Step' & count(*) as StepNbr, A.step
from products as A
inner join products as B
on A.product = B.product
and A.Step >= B.Step
group by A.product, A.step

John Winterbottom wrote:
select A.product, 'Step' & count(*) as StepNbr, A.step
from
(
select product, step
from products
) as A
inner join
(
select product, step
from products
) as B
on A.product = B.product
and A.Step >= B.Step
group by A.product, A.step
Aug 14 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.