sql function递归

alter function Fn_GetUserGroupRelation

(

         @DHsItemID int

)

returns nvarchar(1024)

begin

 

         declare @Col_HsItemID int

         declare @Result nvarchar(1024)

         set @Result=''

         select @Col_HsItemID = Col_HsItemID from Hs_Relation where Col_DHsItemID=@DHsItemID

         if @Col_HsItemID <> 1

         begin

                   set @Result = dbo.Fn_GetUserGroupRelation(@Col_HsItemID) + '#' + convert(nvarchar(1024),@Col_HsItemID)

         end

         return @Result

end

 

---select dbo.Fn_GetUserGroupRelation(7)

posted @ 2013-11-22 15:49  华子的幸福生活  阅读(276)  评论(0编辑  收藏  举报