For this query i am getting similar rows with multiple values. Need to combine values within single row. I tried using Stuff but i am unable to do so. Need to organise data with only SQL functions and no Pl/SQL code if possible.
STUFF((SELECT '| ' + udn1.DisplayName
FROM vUserDisplayName udn1
FOR XML PATH('')), 1, 1, '') [USERS]
SELECT gdn.DisplayName,
,ISNULL(udn.DisplayName, N'No user assigned') AS [User]
FROM tbGroup g
INNER JOIN vGroupDisplayName gdn
ON g.GroupId = gdn.GroupId
LEFT JOIN tbUserGroup ug
ON g.GroupId = ug.GroupId
LEFT JOIN tbUser u
ON ug.UserId = u.UserId
LEFT JOIN vUserDisplayName udn
ON u.UserId = udn.UserId
WHERE
(u.[Enabled] = 1 OR u.UserId IS NULL)
AND
g.IsPersonal = 0
AND
g.SystemGroup = 0
Output :
DisplayName User
a [email protected]
a [email protected]
a [email protected]
b [email protected]
b [email protected]
b [email protected]
c [email protected]
c [email protected]
c [email protected]
Expected Output :
DisplayName User
a [email protected]|[email protected]|[email protected]
b [email protected]|[email protected]|[email protected]
c [email protected]|[email protected]|[email protected]