/*==============================
参数说明:@id  起始类别ID号
TbEnterpriseType 是表名
================================*/
CREATE function FunEnterpriseType(@id int)returns @re table(id int,level int)
as
begin
Declare @l int
Set @l=0
Insert @re select @id,@l
While @@rowcount>0
Begin
set @l=@l+1
insert @re select a.id,@l
from TbEnterpriseType a,@re b
where a.PID=b.id and b.level=@l-1
End
return
End