1. 得到XML类型中某个节点下子节点的数量
DECLARE @xml xml SET @xml = ‘ <Parameters> <Parameter name = "param_executionid" type="Int64" /> <Parameter name = "param_loadfromsourceSP" type="String" /> <Parameter name = "param_loadtoStageTableSP" type="String" /> <Parameter name = "param_objectname" type="String" /> </Parameters>‘; SELECT @xml.value(‘count(/Parameters/Parameter)‘, ‘int‘)
2. 把XML转成Table
DECLARE @xml xml SET @xml = ‘ <Parameters> <Parameter name = "param_executionid" type="Int64" /> <Parameter name = "param_loadfromsourceSP" type="String" /> <Parameter name = "param_loadtoStageTableSP" type="String" /> <Parameter name = "param_objectname" type="String" /> </Parameters>‘; SELECT T.c.query(‘.‘).value(‘(//@name)[1]‘, ‘varchar(50)‘) AS A, T.c.query(‘.‘).value(‘(//@type)[1]‘, ‘varchar(50)‘) AS B FROM @xml.nodes(‘/Parameters/Parameter‘) T(c)
时间: 2024-10-12 19:36:37