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 2008 Forums
 Transact-SQL (2008)
 Tree Walking?

Author  Topic 

crofsx
Starting Member

2 Posts

Posted - 2012-06-20 : 09:17:38
Hello,

I have a table which indicates status information about insurance jobs, fields are as follows...

ID - Job_ID - Status - CreateTime

The CreateTime is the DateTime stamp for the job entering a given status and also the DateTime stamp for the job exiting the previous status.

What I need to get to is a table of the form

Job_ID - Status - StatusStartTime - StatusEndTime

Is this possible in SQL Server 2005? If so, how do you do it?

Thanks,

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-20 : 10:04:25
select *, StatusEndTime = (select min(t2.StatusStartTime) from tbl t2 where t1.Job_ID = t2.Job_ID and t2.StatusStartTime > t1.StatusStartTime)
frrom tbl t1

==========================================
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

crofsx
Starting Member

2 Posts

Posted - 2012-06-21 : 03:31:30
Works perfectly, thanks.
Go to Top of Page
   

- Advertisement -