I've the following table which holds status of jobs in a history table.
JobHistory
jobOrderId | dateAdded | Status
-----------|-------------------------|-------
4909 | 2015-08-26 18:15:07.527 | OPEN
4909 | 2015-08-28 13:35:38.997 | CLOSE
4909 | 2015-08-31 12:16:29.787 | OPEN
4910 | 2015-08-27 12:16:42.72 | OPEN
4910 | 2015-08-28 17:04:43.617 | CLOSE
4910 | 2015-08-31 17:01:27.337 | OPEN
4911 | 2015-08-27 16:08:39.467 | OPEN
I would like to get the following output
jobOrderId | opendate | closedate
-----------|------------|-----------
4909 | 2015-08-26 | 2015-08-28
4909 | 2015-08-31 | NULL
4910 | 2015-08-27 | 2015-08-28
4910 | 2015-08-31 | NULL
4911 | 2015-08-27 | NULL
Can any one suggest me how to get this kind of output using SQL Server 2012 window functions?
Best Answer