Skip to main content
In-lined link; formatted code
Source Link
Paul White
  • 90.3k
  • 30
  • 424
  • 663

Windowed function LAG should give you the answer - :

https://msdn.microsoft.com/enLAG (Transact-us/library/hh231256.aspxSQL). 

This function allows it so you don't have to join to get [current]-nth value

SELECT 
    *,
    LAG([ENTRY_DATE], 1, NULL) OVER (
    OVER (   PARTITION BY [ID], [STATE], [ENTRY_DATE] 
        ORDER BY [ENTRY_DATE]) AS EXIT_DATE
FROM table;

Windowed function LAG should give you the answer - https://msdn.microsoft.com/en-us/library/hh231256.aspx. This function allows it so you don't have to join to get [current]-nth value

SELECT *,
LAG([ENTRY_DATE], 1, NULL) 
    OVER (PARTITION BY [ID], [STATE], [ENTRY_DATE] ORDER BY [ENTRY_DATE]) AS EXIT_DATE
FROM table;

Windowed function LAG should give you the answer:

LAG (Transact-SQL) 

This function allows it so you don't have to join to get [current]-nth value

SELECT 
    *,
    LAG([ENTRY_DATE], 1, NULL) OVER (
        PARTITION BY [ID], [STATE], [ENTRY_DATE] 
        ORDER BY [ENTRY_DATE]) AS EXIT_DATE
FROM table;
Source Link
Tigerjz32
  • 417
  • 3
  • 11

Windowed function LAG should give you the answer - https://msdn.microsoft.com/en-us/library/hh231256.aspx. This function allows it so you don't have to join to get [current]-nth value

SELECT *,
LAG([ENTRY_DATE], 1, NULL) 
    OVER (PARTITION BY [ID], [STATE], [ENTRY_DATE] ORDER BY [ENTRY_DATE]) AS EXIT_DATE
FROM table;