Hi
If we search an XML datatype, does it use the collation properties
from the database, e.g. Case sensitivity, Accent sensitivity?
If it doesn't use the database, is there any other way of affecting
it?
Chloe
Bob Beauchemin - 12 Jun 2009 20:08 GMT
If you use XML in SQL Server 2005 and above, it uses the encoding specified
in the XML document itself to determine how to read the XML into in the
database. The default encoding is UTF-16 and regardless of the encoding that
you specify in the original, SQL Server converts it to UTF-16 when it's
stored. UTF-16 is the only supported output format. The XML data type in SQL
Server does not support collation. Reference
msdn.microsoft.com/en-US/library/ms345117.aspx.
Cheers,
Bob Beauchemin
SQLskills
> Hi
>
[quoted text clipped - 5 lines]
>
> Chloe
Michael Coles - 13 Jun 2009 03:44 GMT
Just to add to what Bob said, XML uses binary comparisons for comparison (in
XQuery) and sorting (the order by clause in FLWOR expressions). Efficient,
but does not account for the little things we've grown accustomed to like
dictionary sorting, accent insensitivity, case insensitivity, etc.

Signature
========
Michael Coles
"Pro T-SQL 2008 Programmer's Guide"
http://www.amazon.com/T-SQL-2008-Programmer-rsquo-Guide/dp/143021001X
> Hi
>
[quoted text clipped - 5 lines]
>
> Chloe
Bob - 14 Jun 2009 22:26 GMT
If you break the XML out into relational data or into a table then you can
use collations, eg
DECLARE @xml XML
SET @xml = '<test case="lower">a</test>
<test case="upper">A</test>'
SELECT *
FROM
(
SELECT
x.y.value('@case','VARCHAR(10)') AS xcase,
x.y.value('.','VARCHAR(10)') AS xvalue
FROM @xml.nodes('//*') x(y)
) x
WHERE xvalue = 'A'
SELECT *
FROM
(
SELECT
x.y.value('@case','VARCHAR(10)') AS xcase,
x.y.value('.','VARCHAR(10)') AS xvalue
FROM @xml.nodes('//*') x(y)
) x
WHERE xvalue = 'A' COLLATE SQL_Latin1_General_CP1_CS_AS
SELECT *
FROM
(
SELECT
x.y.value('@case','VARCHAR(10)') AS xcase,
x.y.value('.','VARCHAR(10)') AS xvalue
FROM @xml.nodes('//*') x(y)
) x
WHERE xvalue = 'a' COLLATE SQL_Latin1_General_CP1_CS_AS
> Hi
>
[quoted text clipped - 5 lines]
>
> Chloe
Michael Coles - 15 Jun 2009 07:56 GMT
But keep in mind shredding can be an expensive operation...

Signature
========
Michael Coles
"Pro T-SQL 2008 Programmer's Guide"
http://www.amazon.com/T-SQL-2008-Programmer-rsquo-Guide/dp/143021001X
> If you break the XML out into relational data or into a table then you can
> use collations, eg
[quoted text clipped - 43 lines]
>>
>> Chloe
Michael Rys [MSFT] - 20 Jul 2009 22:19 GMT
And to add to all the great advise:
If you want us to start supporting collations inside the XQuery, please go
and file a feedback item at http://connect.microsoft.com/sqlserver/feedback
and vote on it ;)
Cheers
Michael
> But keep in mind shredding can be an expensive operation...
>
[quoted text clipped - 42 lines]
>>>
>>> Chloe