Parade: SQL Server 2005 Database list total

Source: Internet
Author: User
Tags insert
server| Data | database

A common problem in Microsoft's SQL Server Forum is whether SQL Server 2005 has aggregate functions similar to sum, but is used for collections of strings. For example, suppose a database has the following tables and data:

CREATE TABLE Strings
(
String VARCHAR (20)
)

INSERT Strings VALUES (' A ')
INSERT Strings VALUES (' B ')
INSERT Strings VALUES (' C ')

It is possible to use the following collection on this table to generate a list of strings:
SELECT Listagg (String)
From Strings

Output:

' A, B, C '

Although this total is not built into SQL Server 2005, the new system still introduces a way to easily achieve this functionality. The most common way is to use the new CLR user-defined totals (UDA). Unfortunately, user-defined totals have a limit of 8,000 bytes, which greatly limits their total application to large collections.

Another way to achieve a goal in SQL Server 2005 is a by-product of the new for XML path function. By making an empty path, it is possible to produce a function that resembles string totals:

SELECT String + ', ' as [text ()]

From Strings

ORDER BY String

For XML PATH (')

More information about this technology can be found on the Aaron Bertrand asp FAQ http://www.aspfaq.com/ website.



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.