我試圖使用本指南讀取SQL Server中的XML文件。在命名空間中讀取SQL Server上的Xml
http://blog.sqlauthority.com/2009/02/13/sql-server-simple-example-of-reading-xml-file-using-t-sql/
工作正常,但我有一個XML文件,命名空間和doesn't的工作原理是代碼命名空間。
一些解決方案?
感謝Remus。現在我有這個代碼
DECLARE @MyXML XML
SET @MyXML = '<cfdi:Comprobante xmlns:cfdi="http://www.sat.gob.mx/cfd/3" Moneda="USD">
<cfdi:Impuestos totalImpuestosRetenidos="0.00" totalImpuestosTrasladados="1143.06">
</cfdi:Impuestos>
</cfdi:Comprobante> '
;with xmlnamespaces('http://www.sat.gob.mx/cfd/3' as cfdi)
SELECT
a.b.value('@Moneda','varchar(100)') Moneda,
a.b.value('Impuestos[1]/@totalImpuestosTrasladados','float') totalImpuestosTraslados
FROM @MyXML.nodes('cfdi:Comprobante') a(b)
有效,但totalImpuestosTraslados的值爲NULL。
莫內達totalImpuestosTraslados
美元NULL