Multiple lines of MySQL and SQL Server merged into one line

Source: Internet
Author: User


Multiple lines of MySQL and SQL Server merged into one line


MySQL Multi-line merge:

MySQL built-in function group_concat (exper SEPARATOR "")

Exper: set forth

SEPARATOR "": line delimiter, which means separating multiple lines with a space


Mysql> select * from tmp_02;

+------------+---------+

| fclient | CT |

+------------+---------+

| Android | 1858799 |

|  IOS | 522568 |

|  Legendary Client | 472561 |

+------------+---------+

3 Rows in Set (0.00 sec)


Multi-line Merge:

Mysql> Select CONVERT (Group_concat (CONCAT (fclient, ': ', CT) SEPARATOR "") using UTF8) TKey from tmp_02;

+-----------------------------------------------+

| TKey |

+-----------------------------------------------+

| Android: 1858799 ios:522568 legendary client: 472561 |

+-----------------------------------------------+

1 row in Set (0.00 sec)


Note: The line delimiter can be any character.


Reference Link: http://blog.sina.com.cn/s/blog_4e808acf01009qna.html



In SQL Server, a previous version of 2000 (including 2000) requires the ability to manually write a function that implements a multiline merge row.

Since 2005 (including 2005) the functionality of the built-in for XML path makes it easy to implement multiple rows of merged lines

Example:

Select EventClass from Dbo.perfom

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/47/B7/wKioL1P-xuKhIbyIAAC7JjzI-xk552.jpg "title=" 1.jpg " alt= "Wkiol1p-xukhibyiaac7jjzi-xk552.jpg"/>


Select (select CAST (eventclass as varchar) + '; '

From DBO.PERFOM FOR XML Path (")) as A

Results:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/47/B7/wKioL1P-xvexgxmmAADLVoeDZv0372.jpg "title=" 2.jpg " alt= "Wkiol1p-xvexgxmmaadlvoedzv0372.jpg"/>


Reference links for the FOR XML path:

Http://www.cnblogs.com/doubleliang/archive/2011/07/06/2098775.html


This article is from the "SQL Server MySQL" blog, so be sure to keep this source http://dwchaoyue.blog.51cto.com/2826417/1546125

Multiple lines of MySQL and SQL Server merged into one line

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.