I have a long-standing problem between SQL 2005 (9.0.5057) and SQL 2012 (11.0.3128). When I run the following sample SQL query on SQL 2005 and then SQL 2012, I get different results:
select
0 'test1/@old', null 'test1',
null 'test2/@old', 2 'test2',
2 'test3/@old', 2 'test3',
null 'test4/@old', null 'test4'
FOR XML PATH('Data'), ELEMENTS XSINIL
For SQL 2005, the result is:
<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<test1 old="0" />
<test2>2</test2>
<test3 old="2">2</test3>
<test4 xsi:nil="true" />
</Data>
For SQL 2012, the result is:
<Data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<test1 old="0" xsi:nil="true" />
<test2>2</test2>
<test3 old="2">2</test3>
<test4 xsi:nil="true" />
</Data>
Test1 is the problem. The behavior for SQL 2012 is correct, but I'm struggling to find a patch or work for it in SQL 2005.
I performed the same test on SQL Server 2008 R2 (10.50.2500), but I get the result of SQL 2005.
Am I missing something?
source
share