For XML Path

Source: Internet
Author: User

Table data created for the usage of the for XML path
Take a look at the initial usage of the FOR XML path: The Select Classid,sex,age,name from #PersonInfo for XML path (' PersonInfo ') can be seen from the name, FOR XML!!!
The feeling is usually used in conjunction with the bad group by. Examples are as follows:
--Statistics of male students over 22 years of age in each class select Classid,count (1) as ' number of over 22 years ', (select Name+ ', ' from #PersonInfo where Classid=p.classid for XML Path (")) as ' name set ' from #PersonInfo p where sex= ' man ' and age>22 Group by ClassID ORDER by Classidselect Classid,age , COUNT (1) as ' more than 22 years old ', (select Name+ ', ' from #PersonInfo where Classid=p.classid and age=p.age for XML Path (")) as ' name collection ' From #PersonInfo p where sex= ' man ' and age>22 Group by Classid,age ORDER by Classidselect Classid,age,count (1) as ' more than 22 years old  Number ', (select Name+ ', ' from #PersonInfo where Classid=p.classid and age=p.age for XML Path (")) as ' name set ' from #PersonInfo p Where sex= ' Men ' GROUP by Classid,age have age>22 order by ClassID

The results are as follows:
The feeling of having the use is not as big as it is imagined. It is only used after group by, and it is the aggregate function that is of great use, otherwise it can be written directly in the back. Add: The comma at the back of the name set can be removed by the stuff function.

For XML Path

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.