28,409
社区成员




CREATE PROCEDURE [f_getChild]
(
@strNum1 VARCHAR(10)
)
as
begin
declare @t table
(
[strNum1] [VARCHAR] (10),
[strNum2] [VARCHAR] (10),
[Level] [INT],
[Ord] [VARCHAR] (100)
)
declare @i int
set @i=1
insert into @t select strNum1,strNum2,@i,right('0'+strNum2,3) from AAA where strNum1 = @strNum1
while @@rowcount <>0
begin
set @i=@i+1
insert into @t
select
a.strNum1,a.strNum2,@i,b.Ord+a.strNum2
from
AAA a,@t b
where
a.strNum1=b.strNum2 and b.Level=@i-1
and
not exists(select 1 from @t where strNum1=a.strNum1 and strNum2=a.strNum2)
end
select * from @t order by Ord
end
go
: