SQL Server combining 2 rows into 1 from the same table

Posted by Maton on Stack Overflow See other posts from Stack Overflow or by Maton
Published on 2010-05-31T05:03:55Z Indexed on 2010/05/31 5:12 UTC
Read the original article Hit count: 291

Filed under:
|
|

Hi, I have a table with an JobID (PK), EmployeeID (FK), StartDate, EndDate containing data such as:

1, 10, '01-Jan-2010 08:00:00', '01-Jan-2010 08:30:00'
2, 10, '01-Jan-2010 08:50:00', '01-Jan-2010 09:05:00'
3, 10, '02-Feb-2010 10:00:00', '02-Feb-2010 10:30:00'

I want to return a record for each EndDate for a Job and then the same employees StartDate for his next immediate job (by date time). So from the data above the result would be

Result 1: 10, 01-Jan-2010 08:30:00, 01-Jan-2010 08:50:00
Result 2: 10, 01-Jan-2010 09:05:00, 02-Feb-2010 10:00:00

Greatly appreciate any help!

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server