我正在尝试使用SQL将XML字段解析为表格,我需要一些帮助。一行的XML字段示例如下:
<MarketValueTransactionVo
objectId="104" statusCode="0" acctNum="60835733" recType="6"
errorFlag="N" sourceCode="0" userId="DATAEXCHANGE" taxItem="0"
amount="4496.79" accountEntityType="0" transactionAmount="4496.79"
importFormatType="5" dateEntered="01252015" clearingFirmBrokerCode="OPSX"
formattedAmount="$4,496.79" totalShares="0" controlNumberSequence="0"
applicableYear="2014" brokerCode="OPSX" ssn="632248334"
entityId="OPSX" entityTypeCode="4" activityApplicationCode="3001"
activityTypeCode="801" entityPresentationNumber="0" checkStatusCode="0"
correctionCode="0" correctionTypeCode="0" entityLOBCode="0"
requestPresentationNumber="0" requestStatusCode="0" reverseReasonCode="0"
loanPresentationNumber="0">
</MarketValueTransactionVo>
答案 0 :(得分:1)
您想要解决XML标记属性。标记属性可以使用符号符号@
来解决,请参阅示例Import XML with Attribute to SQL Server Table和Convert Xml to Table SQL Server(答案中的第二种格式):
SELECT
Tbl.Col.value('@objectId', 'int'),
Tbl.Col.value('@statusCode', 'tinyint'),
Tbl.Col.value('@acctNum', ...proper type int? varchar(xx)? ),
...
FROM @xml.nodes('//MarketValueTransactionVo') Tbl(Col)