SQL Server for XML Path learning

Source: Internet
Author: User

Recently saw too many people ask this kind of question oneself also do not know very much to learn on the net study oneself test

CREATE TABLE test0621 (
ID INT,
NAME NVARCHAR (max)
)

INSERT test0621 VALUES (1, ' AA '), (1, ' BB '), (1, ' CC ')
INSERT test0621 VALUES (2, ' Monday '), (2, ' Tuesday '), (2, ' Wednesday ')

DROP TABLE test0621

SELECT * from test0621

SELECT * from test0621 for XML PATH (")--Delete the row node

SELECT * from test0621 for XML PATH (' xx ')--Change row node to XX

SELECT name+ ', ' from test0621 for XML PATH (')--Custom display

SELECT ID, (
SELECT name+ ', ' from test0621 WHERE id = a.id for XML PATH (')--correlation ID
) as NAME
From test0621 A
GROUP BY a.ID--No group by is displayed as more than one

SQL Server for XML Path learning

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.