日期:2014-05-17 浏览次数:20578 次
DECLARE @i INT
SET @i=2
;WITH cte AS
(
SELECT number
from master..spt_values
WHERE type='p' AND number>0
AND number %(@i+1)=1
)
SELECT * FROM cte
/*
number
-----------
1
4
7
10
13
16
19
22
25
28
31
34
37
40
43
*/
DECLARE @i INT
SET @i=3 --隔开3行
;WITH t AS
(
SELECT 1 as number
union all
select number + @i+1
from t
WHERE number < 10000
)
SELECT *
FROM t
where number < 50
option(maxrecursion 10000)
/*
number
1
5
9
13
17
21
25
29
33
37
41
45
49
*/