大家来看看这个咋整?
比如说 lpz01,lpz03,lpz04
1001 1 3
sql有办法显示为
lpz01,lpz03,lpz04
1001 1 1
1001 2 2
1001 3 3 这样么?
[解决办法]
可以吧。
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
*/