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)