给出以下SQL:
drop table if exists #testXML
create table #testXML (InputXML xml)
insert into #testXML
values ('<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<document>
<table name="tableName1">
<column name="ID">000010313500011171011710001 </column>
<column name="StartDate">10/27/2019</column>
<column name="EndDate">11/02/2019</column>
</table>
</document>')
我正在尝试获得这样的输出:
ID StartDate EndDate
000010313500011171011710001 10/27/2019 11/02/2019
这是我的出发点,但我现在还没完成。
SELECT
px1.tbl.value('@name','nvarchar(50)') as TableName
,px2.col.value('@name','nvarchar(50)') as ColName
from #testXML px
cross apply inputxml.nodes ('/document/table') as px1(tbl)
cross apply inputxml.nodes ('/document/table/column') as px2(col)
这是在SQL Server 2017上。
您的SQL需要进行如下调整
SQL