Casts between XML data types and SQL data types
Casting of SQL data types to XML data types occurs implicitly. The XMLCAST specification simplifies the task of converting an XML value to an SQL data type.
For casting from an XML schema data type to an SQL data type, the XMLCAST specification eliminates the need to serialize an XML value before casting it to an SQL data type. Casting of an XML schema data type to an SQL data type is useful if you want to return the results of the XMLQUERY function as SQL for further processing in an SQL statement, such as comparing XML values to SQL values or using XML values to order result tables.
You can cast the result of XMLQUERY to an SQL data type only when the XQuery expression that is specified in the XMLQUERY function returns a sequence that contains one item.
Implicit casting of an SQL data type to an XML schema type occurs in the XMLEXISTS predicate or the XMLQUERY or XMLTABLE function, when a column value is passed to an XQuery expression. Although you can use the XMLCAST specification to cast an SQL data type to an XML schema data type, it is usually unnecessary.