select number ,(number+4)/5 from master..spt_values where type='p' and number between 1 and 20 number ----------- ----------- 1 1 2 1 3 1 4 1 5 1 6 2 7 2 8 2 9 2 10 2 11 3 12 3 13 3 14 3 15 3 16 4 17 4 18 4 19 4 20 4(20 行受影响)haha
----利用循环: declare @i int set @i=1 while(@i<=20) begin select top 500 * from tb where [primary_key] not in (select ((@i-1)*500) [primary_key] from tb) --sql_statement... set @i=@i+1 end
/*-----------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20(100 行受影响)
*/看先100行就知道 了
select number ,(number+4)/5 from master..spt_values where type='p' and number between 1 and 20
number
----------- -----------
1 1
2 1
3 1
4 1
5 1
6 2
7 2
8 2
9 2
10 2
11 3
12 3
13 3
14 3
15 3
16 4
17 4
18 4
19 4
20 4(20 行受影响)haha
declare @i int
set @i=1
while(@i<=20)
begin
select top 500 * from tb where [primary_key] not in (select ((@i-1)*500) [primary_key] from tb)
--sql_statement...
set @i=@i+1
end