if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ChaokersCN_SysMembership_GetUserRoles]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[ChaokersCN_SysMembership_GetUserRoles]
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE    function ChaokersCN_SysMembership_GetUserRoles(@UserID nvarchar(500))
returns nvarchar(500)
as
begin
     declare @sql nvarchar(500)
	set @sql = isnull(@sql,'')
     select @sql=@sql + ','+[RoleName] from 
	(select u.UserID,role.RoleID,role.RoleName from ChaokersCN_SysMembership_Users u,ChaokersCN_SysMembership_User_R_Role r,ChaokersCN_SysMembership_Roles role where u.UserID=r.UserID and r.RoleID=role.RoleID) as t
 	where UserID=@UserID
     set @sql = stuff(@sql,1,1,'')
     return @sql
end


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

