The XMLAGG function is used to produce a forest of XML elements from a collection of XML elements. XMLAGG is an aggregate function, and produces a single aggregated XML result for all the rows in the query.
In the following query, XMLAGG is used to generate a <name> element for each row, and the <name> elements are ordered by employee name. The ORDER BY clause is specified to order the XML elements:
SELECT XMLELEMENT( NAME Departments, XMLATTRIBUTES ( DepartmentID ), XMLAGG( XMLELEMENT( NAME name, Surname ) ORDER BY Surname ) ) AS department_list FROM Employees GROUP BY DepartmentID ORDER BY DepartmentID; |
This query produces the following result:
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |