I need to pivot one column, in a 2 column result set. For e.g.
The number of email address per Id can vary. Not sure if PIVOT would work for this requirement.
I cannot use a temp table, only a single select query
I need to pivot one column, in a 2 column result set. For e.g.
The number of email address per Id can vary. Not sure if PIVOT would work for this requirement.
I cannot use a temp table, only a single select query
In SQL Server you can use cross apply
combined with for xml path('')
for this purpose:
select distinct t1.Id, t3.EmailAddress
from TABLE t1
cross apply (select t2.EmailAddress+' '
from TABLE t2
where t2.Id=t1.Id for xml path('')
) t3 (EmailAddress)
order by t1.Id