create function dbo.gettypeid(@a int)
--传进来 一个typeid,得到这个typeid的最上级的typeid
--select dbo.gettypeid(11609)
returns varchar(8000)
as
begin
declare @result int
declare @cal int
set set @cal = (select typeparentid from ttype where typeid = @a)
--print @cal
if @cal > 0
begin
select @result = dbo.gettypeid (@cal)
end
else
begin
select @result = @a
end
return @result
--select @str = @str + ',' + cast(telnum as varchar) from infor where age = @a
--set @str = right(@str , len(@str) - 1)
--return(@str)
End
该博客介绍了一个SQL函数,用于在具有parentid的树形表结构中查找指定ID的最高级父ID。通过递归调用函数,可以得到任何一个类型ID的顶层父ID。
286

被折叠的 条评论
为什么被折叠?



