单行分号的电子邮件ID

时间:2013-12-20 03:56:42

标签: sql sql-server

SELECT email_id from A;

给了我

A@g.com     b@g.com     c@g.com

我想要单行输出

A@g.com;b@g.com;c@g.com

3 个答案:

答案 0 :(得分:0)

Select Stuff((Select ','+EmailColumnName from TableName for Xml Path('')),1,1,'');

或者如果你的电子邮件已经在On Row上而不是,,,

Select Replace(EmailColumnName,' ',';') from TableName

答案 1 :(得分:0)

DECLARE @myString as NVARCHAR(MAX) = N''

SELECT @myString = @myString + CASE WHEN @myString = '' THEN '' ELSE ';' END + email_id  FROM A;

SELECT @myString;

答案 2 :(得分:0)