日期:2014-05-17  浏览次数:20479 次

新手求一个获取连续值的方法
RT                              .

------解决方案--------------------
用spt_values
------解决方案--------------------
http://bbs.csdn.net/topics/390599689
------解决方案--------------------
需要一个参照表,最好给出测试数据和期待结果
------解决方案--------------------
你想怎么连续?
------解决方案--------------------

select number from 
spt_values with(nolock)
where type='P'

不过这个表只能获取2047以内的数字,如果想要更多数字,需要建表等方式。
------解决方案--------------------
http://bbs.csdn.net/topics/380249004
------解决方案--------------------

declare @num1 int
set @num1=10  --初始值
declare @num2 int
set @num2=50  --结束值
select number from 
spt_values with(nolock)
where type='P' and number between @num1 and @num2

--结果
number
-----------
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

(41 行受影响)