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.
Author |
Topic |
ashdesai
Starting Member
1 Post |
Posted - 2011-07-01 : 03:59:28
|
I have a table which is as followsAct Code R.code Start date15239 8484 27-JUN-1115239 8484 27-DEC-1115239 8484 29-DEC-11Now i need a query which extracts these 3 columns along with a 4th column which is end date.This end date is the start date of next row.For eg 27-DEC-11 is the end date of first row in the table.How do i do it? |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-07-01 : 04:12:30
|
Use CROSS/OUTER APPLY.SELECT t.[Act Code], t.[R.code], t.[Start date], f.nextDateFROM dbo.Table1 AS tOUTER APPLY (SELECT MIN(w.[Start date]) FROM dbo.Table1 AS w WHERE w.[Act Code],= t.[Act Code] AND w.[R.code] = t.[R.code] AND w.[Start date] > t.[Start date]) AS f(nextDate) N 56°04'39.26"E 12°55'05.63" |
|
|
|
|
|