I'm having an issue with OPENXML in SQL Server 2005 where I'll get no results back if the XML doesn't have every tier available. An example would clear up my question:
So we have XML like this:
<Connection Name="DEFAULT" />'
<Branch Name="A_Branch">
<Leaf Name="A_Leaf.OP" >
<Property Name="A_Property" />
</Leaf>
</Branch>
</Connection>
And the OPENXML puts into into a table variable like this
INSERT INTO @xmlDataTable
SELECT *
FROM OPENXML(@idoc, '/Connection/Branch/Leaf', 2)
WITH (
Connection varchar(100) '../../@Name'
, Branch varchar(100) '../@Name'
, Leaf varchar(100) '@Name'
)
And that works fine! But if you put this XML in:
<Connection Name="DEFAULT">
</Connection>
Then the OPENXML returns nothing, an empty row set.
So I'm really not sure what to do to fix that. I need to account for both scenarios, and the scenario with Branches but no leaves. Any thoughts?