当您删除此代码工作正常<data>
包装,从XML和节点,但是当你添加它,就像下面,我得到0的结果。
-- Declare XML variable
DECLARE @data XML;
-- Element-centered XML
SET @data =
N'
<data xmlns="test.xsd">
<subdata>
<customer>
<id>1</id>
<name>Allied Industries</name>
</customer>
<customer>
<id>2</id>
<name>Trades International</name>
</customer>
</subdata>
</data>';
-- Using the query() method
SELECT T.customer.query('id').value('.', 'INT') AS customer_id,
T.customer.query('name').value('.', 'VARCHAR(20)') AS customer_name
FROM @data.nodes('data/subdata/customer') AS T(customer);
但是,当我做这样的工作正常:
-- Element-centered XML
SET @data =
N'
<subdata>
<customer>
<id>1</id>
<name>Allied Industries</name>
</customer>
<customer>
<id>2</id>
<name>Trades International</name>
</customer>
</subdata>
';
-- Using the query() method
SELECT T.customer.query('id').value('.', 'INT') AS customer_id,
T.customer.query('name').value('.', 'VARCHAR(20)') AS customer_name
FROM @data.nodes('subdata/customer') AS T(customer);
有谁知道为什么我没有在第一个例子中得到结果,当<data>
母公司包装是吗?