日期:2014-05-17 浏览次数:20493 次
DECLARE @t TABLE(a INT,b INT,c int)
INSERT INTO @t SELECT 1001,1,3;
SELECT a,b.number AS b,b.number AS c FROM @t a JOIN master..spt_values b ON b.number BETWEEN a.b AND a.c AND b.type='p'
/*
a b c
----------- ----------- -----------
1001 1 1
1001 2 2
1001 3 3
*/
declare @t table (lpz01 int,lpz03 int,lpz04 int)
insert into @t
select 1001,1,3
;with maco as
(
select lpz01,lpz03,lpz03 as lpz04 from @t
union all
select a.lpz01,a.lpz03+1,a.lpz03+1 from maco a,@t b where a.lpz03<b.lpz04
)
select * from maco
/*
lpz01 lpz03 lpz04
----------- ----------- -----------
1001 1 1
1001 2 2
1001 3 3