CREATE PROCEDURE mysp
@id  int
ASdeclare @t table(myid int,myname varchar(50),pid int)
insert @t select * from test1 where pid=@id
while(@@rowcount>0)
begin
insert @t select a.* from test1 a,@t b where a.pid=b.myid
end
select * from @t
return 
GO
数据库结构为 id int ,name varchar(50),pid int;分别代表编号,名称,父编号