I have this table in SQL:
pid displayname Group
-------------------------------------
d-5454-s34 name Frans
d-5454-s34 sd xyh
d-5454-s34 description Group zen
d-5454-s34 member xxxx
d-5454-s34 member yyyy
d-5454-s34 member zzzzz
d-5454-s34 member uuuuu
d-5454-s45 name He-man
d-5454-s45 sd ygh
d-5454-s45 description Group Comics
d-5454-s45 member eeee
d-5454-s45 member ffffff
e-3434-t45 name Calvin
e-3434-t45 sd trdg
e-3434-t45 description test
and the final output should be
pid name sd descript member
---------------------------------------------------------------------------
d-5454-s34 Frans xyh Group zen xxxx; yyyy; zzzzz; uuuuu
d-5454-s45 He-man ygh Group Comics eeee; ffffff
e-3434-t45 Calvin trdg test NULL
I have used the approach of Taryn that you can see in this link: Sql PIVOT and string concatenation aggregate
... and for now I only want to build the concatenated string so:
SELECT distinct a.pid, a.displayname, LEFT(r.[Description] , LEN(r.[Description])-1) [Description]
FROM [Teste] a
CROSS APPLY
(
SELECT r.[description] + '; '
FROM [Teste] r
where a.[pid] = r.[pid]
and a.[displayname] = r.[displayname]
FOR XML PATH('')
) r ([Description])
but to have the member concatenated is taking lots of time and it throws this error: Could not allocate space for object 'dbo.Large Object Storage System object: 422858089496576' in database 'tempdb' because the 'PRIMARY' filegroup is full.
IF i use a small set (using select top 100 in select r.[description]) it is giving a table like the following (it is only a part of the table):
pid displayname descript
---------------------------------------------------------------------------
d-5454-s34 member xxxx; xxxx; xxxx; xxxx; (and it keeps to repeat)
d-5454-s34 member yyyy; yyyy; yyyy; yyyy; (and it keeps to repeat)
d-5454-s45 member eeee; eeee; eeee; eeee; (and it keeps to repeat)
d-5454-s45 sd ygh; ygh;ygh;ygh;ygh;ygh; (and it keeps to repeat)
it does not show distinct pIds neither, and it repeats the values.. it does not show different values for the member for each id, neither single values for sd, description, and name.