日期:2014-05-16 浏览次数:20390 次
WITH a1 (id)AS
(
SELECT '000000000' UNION ALL
SELECT '000000002' UNION ALL
SELECT '000000003' UNION ALL
SELECT '000000005'
)
,a2 AS
(
SELECT CAST(MAX(id) AS INT) id FROM a1
)
,a3 AS
(
SELECT 0 n,CAST('000000000' AS CHAR(9)) id
UNION ALL
SELECT n+1,CAST(RIGHT('00000000'+CAST(n+1 AS VARCHAR(9)),9) AS CHAR(9))
FROM a3
WHERE n<(SELECT id FROM a2)
)
SELECT id FROM a3
EXCEPT
SELECT id FROM a1
OPTION(MAXRECURSION 0)