0

This should be a simple one but I am having trouble with it. I want to create dynamic seperated list from a table that I have. Example:

Table:

Email
Person1@address.com
Person2@address.com

End result should give me

Person1@address.com;person2@address.com

I am not sure what the right method would be to get these results. i think that I can do it with ForXML but it is pretty complex for what seems to be a simple issue.

Any advice would be appreciated. I will keep messing with the ForXml example I found.

Brian Cascone
  • 157
  • 1
  • 2
  • 13

3 Answers3

2

This should give back the desired results:

SELECT STUFF((SELECT ';'+ Email AS [text()] FROM Person FOR XML PATH('')),1,1,'');

http://sqlfiddle.com/#!3/c3fac/3

JodyT
  • 4,324
  • 2
  • 19
  • 31
1
declare @emailstring varchar(max) = ''

select @emailstring = @emailstring + email + ';'
from tablename

set @emailstring = left(@emailstring,len(@emailstring)-1)
sam yi
  • 4,806
  • 1
  • 29
  • 40
0

It looks like you're using semicolons, so in MySQL you can do

select group_concat(Email SEPARATOR ';')
from   Table

and you're done.

dg99
  • 5,456
  • 3
  • 37
  • 49