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
 Calculating duration time

Author  Topic 

Oz7
Starting Member

8 Posts

Posted - 2007-12-13 : 14:39:18
Hi guys, I am having difficulty calculating the time duration between receiving process to shipping process.
I have a table that consists of: Order#, Processes, Time_In, Time_Out.
Order# can be 1, 2, 3, 4, 5.
While at the same time Order# 1 can go through more than one process, i.e.: Receiving, VisualTest, MechanicalTest, ..., Shipping.
Every Order# does not necessarily goes through all processes, but surely they will go through receiving process and shipping process.
For each process we will have recorded time when the order# comes in and when it finishes with each process.
I need to calculate the length of time from Time_In from Receiving to Time_Out in Shipping.

I.E.:

Order# | Process | Time_In | Time_out
1 | Receiving | 2007-12-1 10:00:00.000 | 2007-12-1 10:10:00.000
1 | Incoming Q.A. | 2007-12-1 10:40:00.000 | 2007-12-1 11:42:00.000
1 | Visual Check | 2007-12-2 08:10:00.000 | 2007-12-2 11:00:00.000
1 | Shipping | 2007-12-2 11:20:00.000 | 2007-12-2 11:52:00.000
2 | xxxxx | xxxxx | xxxxx
2 | xxxxx | xxxxx | xxxxx
2 | xxxxx | xxxxx | xxxxx

Please help.
Thanks in advance.

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-12-13 : 15:17:51
[code]
select
Duration_Seconds = sum(datediff(ss,Time_In,Time_out))
from
MyOrders
where
[Order#] = 1
[/code]

CODO ERGO SUM
Go to Top of Page

Oz7
Starting Member

8 Posts

Posted - 2007-12-13 : 18:15:00
Hi Michael,

If I run your query I'll get the time duration only for Order#1.
I will need to write a query that will calculate the time duration for all Order#.
However, I finally get the answer for this one, but thanks for the help Michael - I appreciate it.

Go to Top of Page
   

- Advertisement -