create function f_pid(@id varchar(3)) returns @t_level TABLE(id varchar(3))
as
begin
insert into @t_level select @id
select @id = pid from tb where id = @id and pid is not null
while @@ROWCOUNT > 0
begin
insert into @t_level select @id
select @id = pid from tb where id = @id and pid is not null
end
return
end
go
as
begin
insert into @t_level select @id
select @id = pid from tb where id = @id and pid is not null
while @@ROWCOUNT > 0
begin
insert into @t_level select @id
select @id = pid from tb where id = @id and pid is not null
end
return
end
go
一般为说,类似需求使用生成一个临时表以传递记录。