Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - SQL Usage » XML in the database » Query results as XML » Use of the FOR XML clause to retrieve query results as XML

 

FOR XML examples

The following examples show how the FOR XML clause can be used in a SELECT statement.

  • The following example shows how the FOR XML clause can be used in a subquery:

    SELECT XMLELEMENT( NAME root,
        (SELECT * FROM Employees FOR XML RAW) );
  • The following example shows how the FOR XML clause can be used in a query with a GROUP BY clause and aggregate function:

    SELECT Name, AVG(UnitPrice) AS Price
    FROM Products
    GROUP BY Name
    FOR XML RAW;
  • The following example shows how the FOR XML clause can be used in a view definition:

    CREATE VIEW EmployeesDepartments
    AS SELECT Surname, GivenName, DepartmentName
    FROM Employees JOIN Departments
    ON Employees.DepartmentID = Departments.DepartmentID
    FOR XML AUTO;