I have a large XML file that I would like to get into SQL Server so I query it in a readable format for an end user. I have made a start on a query and i can get some data but unable to get the rest.
This is a sample set of data from my xml file
<file>
<edxMsg>
<edxMsgHdr>
<trnNm>ICSHDR2</trnNm>
<trnAct>N</trnAct>
<trnVer>01</trnVer>
<rcvAgncy>PLA</rcvAgncy>
<rcvAgncyObjId>555012069A</rcvAgncyObjId>
<sndAgncy>CLK</sndAgncy>
<sndAgncyApplnId>ICS</sndAgncyApplnId>
<sentDate>20180920</sentDate>
<sentTime>013113615000</sentTime>
<sendGMTOffsetMin>-600</sendGMTOffsetMin>
<sndMchnId>N</sndMchnId>
<trnRefId>37</trnRefId>
</edxMsgHdr>
<trnData>
<batchInfo>
<numRecords>1151</numRecords>
</batchInfo>
</trnData>
</edxMsg>
<edxMsg>
<edxMsgHdr>
<trnNm>ICS400CUR</trnNm>
<trnAct>N</trnAct>
<trnVer>01</trnVer>
<rcvAgncy>PLA</rcvAgncy>
<rcvAgncyObjId>2015</rcvAgncyObjId>
<sndAgncy>CLK</sndAgncy>
<sndAgncyObjId>204630959S</sndAgncyObjId>
<sndAgncyApplnId>ICS</sndAgncyApplnId>
<sndUserId>PLAN-AAD192</sndUserId>
<sentDate>20180919</sentDate>
<sentTime>131812085000</sentTime>
<sendGMTOffsetMin>-600</sendGMTOffsetMin>
<sndMchnId>N</sndMchnId>
<trnRefId>37</trnRefId>
</edxMsgHdr>
<trnData>
<respCurrent>
<freeText>2015</freeText>
<rqstDate>20180919</rqstDate>
<rqstBtch>5575</rqstBtch>
<dob>19690328</dob>
<surname>Knocksville</surname>
<firstname>Jonny</firstname>
<procDts>20180919131812057</procDts>
<partner>N</partner>
<tpId>555012069A</tpId>
<numChild>1</numChild>
<shCareDtl>
<chId>1</chId>
<shPercent>100</shPercent>
</shCareDtl>
<maxRateDtl>
<maxRateBen>DSP</maxRateBen>
<maxRateInd>Y</maxRateInd>
</maxRateDtl>
<maxRateDtl>
<maxRateBen>FTB</maxRateBen>
<maxRateInd>Y</maxRateInd>
</maxRateDtl>
<payDtl>
<paySts>PYD</paySts>
<payType>REG</payType>
<ben>DSP</ben>
<grntDate>20100817</grntDate>
<payDate>20180914</payDate>
<payFreq>2WE</payFreq>
<payActAmt>90760</payActAmt>
<cmpDtl>
<cmp>BASIC</cmp>
<cmpPayAmt>82620</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>CES</cmp>
<cmpPayAmt>1410</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>PNSUP</cmp>
<cmpPayAmt>6730</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
</payDtl>
<payDtl>
<paySts>PYD</paySts>
<payType>REG</payType>
<ben>FTB</ben>
<grntDate>20000701</grntDate>
<payDate>20180907</payDate>
<payFreq>2WE</payFreq>
<payLegAmt>51128</payLegAmt>
<payActAmt>51128</payActAmt>
<cmpDtl>
<cmp>FTBA</cmp>
<cmpPayAmt>23786</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>FTBA</cmp>
<cmpPayAmt>23786</cmpPayAmt>
<cmpPayCode>LEG</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>FTBB</cmp>
<cmpPayAmt>10864</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>FTBB</cmp>
<cmpPayAmt>10864</cmpPayAmt>
<cmpPayCode>LEG</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>CESA</cmp>
<cmpPayAmt>448</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>CESA</cmp>
<cmpPayAmt>448</cmpPayAmt>
<cmpPayCode>LEG</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>CESB</cmp>
<cmpPayAmt>196</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>CESB</cmp>
<cmpPayAmt>196</cmpPayAmt>
<cmpPayCode>LEG</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>RA</cmp>
<cmpPayAmt>15834</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>RA</cmp>
<cmpPayAmt>15834</cmpPayAmt>
<cmpPayCode>LEG</cmpPayCode>
</cmpDtl>
</payDtl>
<payDtl>
<paySts>NXT</paySts>
<payType>REG</payType>
<ben>DSP</ben>
<grntDate>20100817</grntDate>
<payDate>20180928</payDate>
<payFreq>2WE</payFreq>
<payActAmt>91195</payActAmt>
<cmpDtl>
<cmp>BASIC</cmp>
<cmpPayAmt>83030</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>CES</cmp>
<cmpPayAmt>1410</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>PNSUP</cmp>
<cmpPayAmt>6755</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
</payDtl>
<payDtl>
<paySts>NXT</paySts>
<payType>REG</payType>
<ben>FTB</ben>
<grntDate>20000701</grntDate>
<payDate>20180921</payDate>
<payFreq>2WE</payFreq>
<payLegAmt>51128</payLegAmt>
<payActAmt>51128</payActAmt>
<cmpDtl>
<cmp>FTBA</cmp>
<cmpPayAmt>23786</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>FTBA</cmp>
<cmpPayAmt>23786</cmpPayAmt>
<cmpPayCode>LEG</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>FTBB</cmp>
<cmpPayAmt>10864</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>FTBB</cmp>
<cmpPayAmt>10864</cmpPayAmt>
<cmpPayCode>LEG</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>CESA</cmp>
<cmpPayAmt>448</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>CESA</cmp>
<cmpPayAmt>448</cmpPayAmt>
<cmpPayCode>LEG</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>CESB</cmp>
<cmpPayAmt>196</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>CESB</cmp>
<cmpPayAmt>196</cmpPayAmt>
<cmpPayCode>LEG</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>RA</cmp>
<cmpPayAmt>15834</cmpPayAmt>
<cmpPayCode>ACT</cmpPayCode>
</cmpDtl>
<cmpDtl>
<cmp>RA</cmp>
<cmpPayAmt>15834</cmpPayAmt>
<cmpPayCode>LEG</cmpPayCode>
</cmpDtl>
</payDtl>
<ddnDtl>
<ddnBen>DSP</ddnBen>
<ddnType>RCV</ddnType>
<ddnAmt>9900</ddnAmt>
<ddnDate>20180914</ddnDate>
</ddnDtl>
<ddnDtl>
<ddnBen>DSP</ddnBen>
<ddnType>DDF</ddnType>
<ddnAmt>47319</ddnAmt>
<ddnDate>20180914</ddnDate>
</ddnDtl>
<ddnDtl>
<ddnBen>FTB</ddnBen>
<ddnType>RCV</ddnType>
<ddnAmt>6034</ddnAmt>
<ddnDate>20180907</ddnDate>
</ddnDtl>
<ddnDtl>
<ddnBen>FTB</ddnBen>
<ddnType>DDF</ddnType>
<ddnAmt>3000</ddnAmt>
<ddnDate>20180907</ddnDate>
</ddnDtl>
<incDtl>
<incType>FIN</incType>
<incFreq>ANN</incFreq>
<incAmt>525</incAmt>
<incDate>20150320</incDate>
</incDtl>
<assDtl>
<assType>CIS</assType>
<assAmt>30000</assAmt>
<assDate>20160920</assDate>
</assDtl>
<assDtl>
<assType>HPE</assType>
<assAmt>1000000</assAmt>
<assDate>20100817</assDate>
</assDtl>
</respCurrent>
</trnData>
</edxMsg>
</file>
This is my current code
DECLARE @x xml
SELECT @x = P
FROM OPENROWSET (BULK 'C:\Temp\XML\CCesResponse.xml', SINGLE_BLOB) AS Tenants (P)
SELECT @x
DECLARE @hdoc int
EXEC sp_xml_preparedocument @hdoc OUTPUT, @x
SELECT *
FROM OPENXML (@hdoc, 'file/edxMsg/trnData/respCurrent', 2)
WITH
(dob varchar(100),
firstname varchar(100),
surname varchar(100),
payDtl varchar(500)
)
I am trying to get a column for each of the following
file/edxMsg/trnData/respCurrent/payDtl/cmpDtl
I have tried what I think is everything but I must be missing something.
Any guidance would be great..