Note that there are some explanatory texts on larger screens.

plurals
  1. POBuild Xml document from SQL Query using For Xml clause
    primarykey
    data
    text
    <p>I'm using AdventureWorks Database and I'd like to build xml block using query with FOR XML clause but i need to specify specific XML Schema in the result to have its datatypes and so on..</p> <p>e.g. this sample query " copied "</p> <pre><code> SELECT e.EmployeeID, c.FirstName, c.MiddleName, c.LastName FROM HumanResources.Employee e INNER JOIN Person.Contact c ON c.ContactID = e.ContactID WHERE c.FirstName = 'Rob' FOR XML RAW ('Employee'), ROOT ('Employees'), ELEMENTS XSINIL, XMLSCHEMA; </code></pre> <p>gets this result</p> <pre><code>&lt;Employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;xsd:schema targetNamespace="urn:schemas-microsoft-com:sql:SqlRowSet1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes" elementFormDefault="qualified"&gt; &lt;xsd:import namespace="http://schemas.microsoft.com/sqlserver/2004/sqltypes" schemaLocation="http://schemas.microsoft.com/sqlserver/2004/sqltypes/sqltypes.xsd" /&gt; &lt;xsd:element name="Employee"&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; &lt;xsd:element name="EmployeeID" type="sqltypes:int" nillable="1" /&gt; &lt;xsd:element name="FirstName" nillable="1"&gt; &lt;xsd:simpleType sqltypes:sqlTypeAlias="[AdventureWorks].[dbo].[Name]"&gt; &lt;xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52"&gt; &lt;xsd:maxLength value="50" /&gt; &lt;/xsd:restriction&gt; &lt;/xsd:simpleType&gt; &lt;/xsd:element&gt; &lt;xsd:element name="MiddleName" nillable="1"&gt; &lt;xsd:simpleType sqltypes:sqlTypeAlias="[AdventureWorks].[dbo].[Name]"&gt; &lt;xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52"&gt; &lt;xsd:maxLength value="50" /&gt; &lt;/xsd:restriction&gt; &lt;/xsd:simpleType&gt; &lt;/xsd:element&gt; &lt;xsd:element name="LastName" nillable="1"&gt; &lt;xsd:simpleType sqltypes:sqlTypeAlias="[AdventureWorks].[dbo].[Name]"&gt; &lt;xsd:restriction base="sqltypes:nvarchar" sqltypes:localeId="1033" sqltypes:sqlCompareOptions="IgnoreCase IgnoreKanaType IgnoreWidth" sqltypes:sqlSortId="52"&gt; &lt;xsd:maxLength value="50" /&gt; &lt;/xsd:restriction&gt; &lt;/xsd:simpleType&gt; &lt;/xsd:element&gt; &lt;/xsd:sequence&gt; &lt;/xsd:complexType&gt; &lt;/xsd:element&gt; &lt;/xsd:schema&gt; &lt;Employee xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1"&gt; &lt;EmployeeID&gt;4&lt;/EmployeeID&gt; &lt;FirstName&gt;Rob&lt;/FirstName&gt; &lt;MiddleName xsi:nil="true" /&gt; &lt;LastName&gt;Walters&lt;/LastName&gt; &lt;/Employee&gt; &lt;Employee xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1"&gt; &lt;EmployeeID&gt;168&lt;/EmployeeID&gt; &lt;FirstName&gt;Rob&lt;/FirstName&gt; &lt;MiddleName&gt;T&lt;/MiddleName&gt; &lt;LastName&gt;Caron&lt;/LastName&gt; &lt;/Employee&gt; &lt;/Employees&gt; </code></pre> <p>i need to refer to another online schema .. is that possible ?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload