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
 Other Forums
 SQL Server 6.5 \ SQL Server 7.0
 Calculating Time Diff between this row and the nex

Author  Topic 

rickni
Starting Member

1 Post

Posted - 2012-12-18 : 19:08:08
I need to write a query calculating time between this row's task and next row's task.

datetime task description timespent
1/1/2012 00:50:12.5 Status Work1
1/1/2012 00:54:13.4 Status Break3
1/1/2012 01:07:29.5 Status Work2

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-12-19 : 03:53:59
select *, datetime - (select min(datetime) from tbl t2 where t2.datetime > t.datetime)
from tbl t
order by datetime

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -