Lately I was blown by xml for SQL Server, but this one here gets me nuts
DECLARE @xml XML;
SET @xml = '
<ROOT>
<Object>
<FooProperty1>123</FooProperty1>
<FooProperty2>456</FooProperty2>
</Object>
<Object>
<FooProperty1>123</FooProperty1>
<FooProperty2>456</FooProperty2>
</Object>
</ROOT>
';
SELECT [doc].[FooProperty1].value('.', 'INT') AS [fooProperty1],
[doc].[FooProperty2].value('.', 'INT') AS [fooProperty2]
FROM @xml.nodes('/ROOT/Object')
AS [doc]
(
[FooProperty1],
[FooProperty2]
)
Gives me
Msg 8159, Level 16, State 1, Line 22 'doc' has fewer columns than were specified in the column list.
Does msg does not change if I change change @xml as
SET @xml = '
<ROOT>
<Object FooProperty1="123" FooProperty2="456"/>
<Object FooProperty1="123" FooProperty2="456"/>
</ROOT>
';