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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Comparing dates from different rows and columns

Author  Topic 

nick604r
Starting Member

3 Posts

Posted - 2006-12-13 : 12:47:44
I've got a query that I need help with. This is a simplified version of the table I have.

sellerID, orderID, time1, time2, time3, time4
1, 1b1, 11:30 11:35 11:40 11:45
1, 1b2, 11:50 11:55 12:00 12:05
1, 1b3, 12:10 12:15 12:20 12:25
2, 1c1, 11:20 11:25 11:30 11:35
2, 1c2, .... and so on

What I want is a datediff between time4 of the previous OrderID to time1 of the current orderID within the same sellerID.

What I want is the following output

sellerID, orderID, timeDif1(time1 current row-time4 previous row), timeDif2(time2-time1), TimeDif3(time3-time2), timeDif4(Time4-time3)

1, 1b1, (11:30- null), (11:35-11:30)5mins, (11:40-11:35)5mins, (11:45-11:40)5mins
1, 1b2, (11:50-11:45*previous row)5 mins, (11:55-11:50)5 mins, ...

Any help would be appreciated!!
THanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-13 : 13:05:40
I think you mean

1, 1b1, 15mins, 5mins, 5mins, 5mins

right?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

nick604r
Starting Member

3 Posts

Posted - 2006-12-13 : 14:08:59
Sorry I made a mistake in my post, please reread the edited version
Go to Top of Page
   

- Advertisement -