Karim DIOUF
Karim DIOUF

Reputation: 3

How to have output result select in a list with sql server as listagg in Oracle

I have a field with multi value with diffent IDs For example :

ID | Email|
+--+------+
|1 |a@mail|
|2 |b@mail|
|3 |c@mail|

I would like to have this output

|Email             |
-------------------+
|a@mail;b@mail;c@mail|

I tried with STUFF and XML PATH based on this post ListAGG in SQLSERVER but I does not work.

Any help will be appreciated

Best Regards

Upvotes: 0

Views: 46

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269643

This should work in SQL Server:

select stuff( (select ';' + email
               from t
               for xml path (''), type
              ).value('.', 'nvarchar(max)'
                     ), 1, 1, ''
            )

Upvotes: 2

Related Questions