How can I get the second column with the same column name using OPENXML in MSSQL 2005?
Here is the result set that I plan to get.
columnData1 columnData2
A B
C D
E F
DECLARE @hDoc int, @xmldata varchar(max)
SELECT @xmldata =
'<?xml version="1.0" encoding="utf-8" ?>
<reportResponse>
<reportDataRow rowNum="1">
<columnData colNum="1">
<data>A</data>
</columnData>
<columnData colNum="2">
<data>B</data>
</columnData>
</reportDataRow>
<reportDataRow rowNum="2">
<columnData colNum="1">
<data>C</data>
</columnData>
<columnData colNum="2">
<data>D</data>
</columnData>
</reportDataRow>
<reportDataRow rowNum="3">
<columnData colNum="1">
<data>E</data>
</columnData>
<columnData colNum="2">
<data>F</data>
</columnData>
</reportDataRow>
</reportResponse>'
EXEC sp_xml_preparedocument @hDoc OUTPUT, @xmldata
SELECT *
FROM OPENXML(@hDoc, '/reportResponse/reportDataRow',2)
WITH (columnData varchar(50) , columnData2 varchar(50) )
SELECT *
FROM OPENXML(@hDoc, '/reportResponse/reportDataRow/columnData',2)
WITH (data varchar(50))
EXEC sp_xml_removedocument @hDoc