--SELECT UserName,BankName,AccessType FROM [BUDGET].[dbo].[TBLBNK_ACCESS]
drop table #temp1
SELECT UserName ,BankName,
AccessType =
STUFF ( ( SELECT ','+InrTab.AccessType
FROM [TBLBNK_ACCESS] InrTab
WHERE InrTab.UserName = OutTab.UserName AND InrTab.BankName = OutTab.BankName
ORDER BY InrTab.AccessType
FOR XML PATH(''),TYPE
).value('.','VARCHAR(MAX)')
, 1,1,SPACE(1)) into #temp1
FROM [TBLBNK_ACCESS] OutTab
GROUP BY OutTab.UserName , OutTab.[BankName] ;
select * from #temp1
drop table #temp1
SELECT UserName ,BankName,
AccessType =
STUFF ( ( SELECT ','+InrTab.AccessType
FROM [TBLBNK_ACCESS] InrTab
WHERE InrTab.UserName = OutTab.UserName AND InrTab.BankName = OutTab.BankName
ORDER BY InrTab.AccessType
FOR XML PATH(''),TYPE
).value('.','VARCHAR(MAX)')
, 1,1,SPACE(1)) into #temp1
FROM [TBLBNK_ACCESS] OutTab
GROUP BY OutTab.UserName , OutTab.[BankName] ;
select * from #temp1