WITH q AS
(
SELECT startId, endId
FROM ranges
UNION ALL
SELECT startId + 1, endId
FROM q
WHERE startId < endId
)
SELECT startId
FROM q
OPTION (MAXRECURSION 0)
WITH q AS
(
SELECT startId, endId
FROM ranges
UNION ALL
SELECT startId + 1, endId
FROM q
WHERE startId < endId
)
SELECT startId
FROM q
OPTION (MAXRECURSION 0)