Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Other Forums
 SQL Server 6.5 \ SQL Server 7.0
 Calculating Time Diff between this row and the nex
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rickni
Starting Member

USA
1 Posts

Posted - 12/18/2012 :  19:08:08  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 12/19/2012 :  03:53:59  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
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
  Previous Topic Topic Next 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.04 seconds. Powered By: Snitz Forums 2000