I have data in the following form that needs to be combined such that I create a single row from two rows of the input data where the second column is the value of the next row less one day.
I've struggled trying to come up with a way to do this, but not gotten very far. I hope this illustration explains the problem:
Table structure
CREATE TABLE Process(
ProcessOrder int NOT NULL IDENTITY (1, 1),
ProcessDate date NOT NULL
);
Query
SELECT ProcessOrder, ProcessDate From Process ORDER BY ProcessOrder;
Data
ProcessOrder ProcessDate
------------ -----------
208 2016-01-04
209 2016-01-11
210 2016-01-18
211 2016-01-25
212 2016-02-01
213 2016-02-08
I need to get the above data into the following shape (note that ProcessEnd is one day less than ProcessBegin from the subsequent record):
ProcessOrder ProcessBegin ProcessEnd
------------ ------------ ----------
208 2016-01-04 2016-01-10
209 2016-01-11 2016-01-17
210 2016-01-18 2016-01-24
211 2016-01-25 2016-01-31
212 2016-02-01 2016-02-07
213 2016-02-08 *NULL*
EDIT
I am guaranteed that values in the ProcessOrder column are consecutive with no missing values.