Q&A for professional and enthusiast programmers
;WITH Missing (missnum, maxid) AS ( SELECT 0 AS missnum, (select max(id) from Users) UNION ALL SELECT missnum + 1, maxid FROM Missing WHERE missnum < maxid ) SELECT missnum FROM Missing LEFT OUTER JOIN Users u on u.id = Missing.missnum WHERE u.id is NULL ORDER BY missnum ASC OPTION (MAXRECURSION 0);