You can use APPLY
:
SELECT t.ID, MIN(t.startdate) AS StartDate, MAX(t.Enddate) AS EndDate
FROM table t OUTER APPLY
( SELECT TOP (1) t1.Enddate
FROM table t1
WHERE t1.id = t.id AND t1.startdate >= t.startdate AND t1.enddate IS NOT NULL
ORDER BY t1.startdate
) t1
GROUP BY t.ID, t1.Enddate;
solved SELECT Record that have start date and enddate [closed]