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
[email protected]
[email protected]

End result should give me

[email protected];[email protected]

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.

0

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

1
declare @emailstring varchar(max) = ''

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

set @emailstring = left(@emailstring,len(@emailstring)-1)

Comments

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.

2 Comments

Note the tsql tag.
@JDB Good call. I should probably turn off my GreaseMonkey script that hides offensive text whilst browsing stackexchange. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.