I have a table address
and another addressline
. One address can have multiple address lines.
I want a select statement that returns one row per address, and if there are multiple address lines, I still only want one row but with all the address lines comma-separated in one column.
I have only managed to do it like this but it returns the values as XML and I just want it as string
SELECT
STUFF((SELECT ', ', adrline.AddressLine
FROM AddressLine AS adrline
WHERE adr.Id = adrline.AddressId
FOR XML PATH('')), 1, 2, '') AS AddressLine,
FROM
Address AS adr
Result:
<AddressLine>My Street 1</AddressLine>, <AddressLine>My Street 2</AddressLine>
Desired result:
My Street 1, My Street 2
How can I do this?