Hi Frndz,
Functionality: Merge field name with comma separator
To achieve this task
Use one fuction that returns merge value with comma separator
Use COALESCE to merge group name
Logic:
Call JoinGroup Name function
select *,dbo.JoinGropupName(tbl.memberid) as groupname
from Table1 as tbl
Function
ALTER FUNCTION [dbo].[JoinGropupName](@MemberID int)
RETURNS VARCHAR(MAX)
AS
BEGIN
-- Declare the return variable here
DECLARE @ReturnValue as Varchar(MAX)
select
@ReturnValue= COALESCE(@ReturnValue + ',', '') + grp.GroupName
from
Table12 as Config
inner join Table1 as mem on Config.memberid = mem.memberid
inner join Table2 as grp on Config.groupid = grp.GID
where
mem.memberid = @MemberID
-- Return the result of the function
RETURN @ReturnValue
END
Hope this helpful!
Thanks