dpav29
asked on
One text string instead of multiple rows
Hi,
I am trying to get one string of email addresses seperated by semi-colon so I can paste it into an email address field. I can get the data in rows:
1 joe@gmail.com
2 sall@verizon.net
3 Mary@yahoo.com
I want one string returned 'joe@gmail.com;sall@verizo n.net;Mary @yahoo.com '
I have searched and found some similar things, but all involved PHP or some other programming I'm not familiar with. I'm using SQL Management Studio 2008 and I am trying to do this using TSQL. . . I thought it would be easy, but. . .not so much.
Thanks in advance for any assistance!
I am trying to get one string of email addresses seperated by semi-colon so I can paste it into an email address field. I can get the data in rows:
1 joe@gmail.com
2 sall@verizon.net
3 Mary@yahoo.com
I want one string returned 'joe@gmail.com;sall@verizo
I have searched and found some similar things, but all involved PHP or some other programming I'm not familiar with. I'm using SQL Management Studio 2008 and I am trying to do this using TSQL. . . I thought it would be easy, but. . .not so much.
Thanks in advance for any assistance!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wow! It worked with virtually no effort on my part! :
select Stuff(
(Select ';' + pe.Email
from ProjectEntities pe
inner join EntityContracts ec
on pe.ProjectEntityId = ec.ProjectEntityId
where ec.ContractId = 97
and pe.Email is not null
and Not (pe.Email = '')
For xml Path('')
)
, 1, 1, '') as Emails
Thanks so much for the fast response and perfect solution!
select Stuff(
(Select ';' + pe.Email
from ProjectEntities pe
inner join EntityContracts ec
on pe.ProjectEntityId = ec.ProjectEntityId
where ec.ContractId = 97
and pe.Email is not null
and Not (pe.Email = '')
For xml Path('')
)
, 1, 1, '') as Emails
Thanks so much for the fast response and perfect solution!
ASKER
Very quick response . . thank you!
select Stuff(
(Select ',' + EmailAddress
From Table1
For xml Path('')
)
, 1, 1, '') as Emails