-- 通过一个子级ID 返回一级分类名称
alter function calcclass
(@dclassid as
int)
returns varchar(50)
as
begin
-- 通过一个子级ID 返回一级分类名称
-- 返回ID
和父级分类ID 直到父级分类ID=0
declare @cid int
declare @cfatherid int
set
@cid=@dclassid
while (@cid>0)
select @cfatherid=cid,@cid=cfatherid from
trd_archivesclass where cid=@cid
return (select cname from trd_archivesclass
where cid=@cfatherid)
end
原文:http://www.cnblogs.com/z5337/p/3658175.html