Using XML in SQL Server and Azure SQL Database: (06) Creating XML from Relational Data

Sign in to queue

The Discussion

  • User profile image

    At around 23:15 in the video, the demonstration shows XML from the subquery being represented as escaped text (with < and > entities replacing the angle brackets).

    I think the simplest way to override this XML-as-text behaviour is to specify that you want an XML type, amending the FOR XML PATH clause in the subquery with ", TYPE":

    FOR XML PATH(''), ROOT('items'), TYPE),

    This should result in the entire XML document being produced:

      <customer id="29847" />
        <item productid="836" />
        <item productid="822" />

Add Your 2 Cents