For XML Path, forxmlpath

Source: Internet
Author: User

For XML Path, forxmlpath
Table data created by using For XML Path
First, let's take a look at the initial usage of for xml path: select ClassID, Sex, Age, Name from # PersonInfo for xml path ('personinfo'). The usage can be seen from the Name, for xml !!!
It is usually used together by group. Example:

-- COUNT the select ClassID, COUNT (1) as 'number older than 22', (select Name + ', 'From # PersonInfo where ClassID = p. classID for xml path ('') as 'name set from # PersonInfo p where Sex = 'male' and Age> 22 group by ClassID order by ClassIDselect ClassID, Age, COUNT (1) as 'number older than 22', (select Name + ', 'From # PersonInfo where ClassID = p. classID and Age = p. age for xml path ('') as 'name set from # PersonInfo p where Sex = 'male' and Age> 22 group by ClassID, Age order by ClassIDselect ClassID, Age, COUNT (1) as 'number older than 22', (select Name + ', 'From # PersonInfo where ClassID = p. classID and Age = p. age for xml path ('') as 'name set from # PersonInfo p where Sex = 'male' group by ClassID, Age having Age> 22 order by ClassID

The result is as follows:
Having is not as useful as you think. It is useful only after group by and is an aggregate function. Otherwise, it can be directly written after where. Note: The comma at the end of the name set can be removed using the stuff function.

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.