--测试表
create table pza(起始号 int, 截止号 int, 份数 int)
create table pzb (票证号码 int)
--测试数据
insert into pza
select 15, 19, 5 union all
select 21, 24, 4
--存储过程
create PROCEDURE tt
as
declare @iB int, @iE int
declare cb cursor for
select 起始号,截止号 from pza
open cb
fetch next from cb into @iB, @iE
while (@@fetch_status <> -1)
begin
while @iB < @iE+1
begin
insert into pzb values (@iB)
set @iB = @iB + 1
end
fetch next from cb into @iB, @iE
end
close cb
deallocate cb
--执行
exec tt
--查询结果
select * from pzb
--结果如下
票证号码
15
16
17
18
19
21
22
23
24