create proc return_id
@str varchar(3)--用户号
as
begin
declare @i int
declare @temp table(id varchar(3),fg int)
select @i=1
insert into @temp values(@str,@i)
while (select count(1) from @temp where fg=@i)<>''
begin
insert into @temp
select yh_id ,fg=@i+1 from yh_gx where p_id in (select id from @temp where fg=@i)
select @i=@i+1
declare @i int
declare @temp table(id varchar(3),fg int)
select @i=1
insert into @temp values('001',@i)
while (select id from @temp where fg=@i)<>''
begin
insert into @temp
select yh_id ,fg=@i+1 from #tb where p_id in (select id from @temp where fg=@i)
select @i=@i+1