CREATE function f_getchildid(@id int)
returns @re table(id int,pid int,name varchar(20))
as
begin
insert into @re values (@id,@id,'父级')
insert into @re select id,parentid,CC_name from SWP_ColConfig where parentid=@id
while @@rowcount>0
insert into @re select a.id,a.parentid,a.CC_name
from SWP_ColConfig a inner join @re b on a.parentid=b.id
where a.id not in(select id from @re)
return
end