SQL Server Forums
Profile | Register | 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
 New Topic  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
3355 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  
 New 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.3 seconds. Powered By: Snitz Forums 2000