WITH numbers (NUM, maxid)
AS
(
SELECT 1 AS num, (select max(id) from tableT)
UNION ALL
SELECT num + 1, maxid FROM numbers
WHERE num < maxid
)
SELECT num
FROM numbers
left outer join tableT on tableT.id = numbers.num
where tablet.id is NULL
OPTION (MAXRECURSION 0);
|