SQL Stitching multiple field values & a field multiple record stitching

Source: Internet
Author: User

such as the student table:

StudentID

Studentname

Studentscore

01

Alice

90

02

Bill

95

03

Cindy

100

One, stitching the values of multiple fields Select Studentid+ '-' +studentname+ '-' +studentscore as studentinfo from student result: Second field multiple records of splicing select stuff ( (SELECT ' | ') +studentname from Student for XML Path (")), 1, 1, ') Results: parsing:

①stuff:
2. Use
Stuff (param1, startIndex, length, param2)
Remove the length characters from the param1 in the startindex (all SQL starts with 1, not 0), and then replace the deleted characters with param2.

2. Parameters
param1
A character data expression. A param1 can be a constant, a variable, a character column, or a binary data row.
StartIndex
An integer value that specifies the start position of the delete and insert. If startindex or length is negative, an empty string is returned. If startindex is longer than param1, an empty string is returned. StartIndex can be of type bigint.
Length
An integer that specifies the number of characters to delete. If length is longer than param1, it is deleted to the last character in param1. Length can be a bigint type.

3. Return type
If PARAM1 is a supported character data type, character data is returned. If PARAM1 is a supported binary data type, binary data is returned.
4. Remarks
If the result value is greater than the maximum value supported by the return type, an error is generated.

②for XML Path:

For XML Path Some people may know that some people may not know, in fact, it is the query result set is presented in XML form, with it we can simplify our query statement implementation of some previously may need to rely on the function of a live stored procedure to complete the work.

Source: http://blog.csdn.net/rolamao/article/details/7745972

SQL Stitching multiple field values & a field multiple record stitching

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.