I have a table where one of the fields is an XML
ThestructureofXMListheBrazilianstandardschemaofCTE(KnowledgeofElectronicTransport)
<cteProcxmlns="http://www.portalfiscal.inf.br/cte" versao="2.00">
<CTe xmlns="http://www.portalfiscal.inf.br/cte">
<infCte versao="2.00" Id="CTe0000000000000000000000000000000">
<ide>
<cUF>10</cUF>
<cCT>00040034</cCT>
<CFOP>5353</CFOP>
<natOp>0</natOp>
<forPag>2</forPag>
<mod>57</mod>
</ide>
<compl>
<xObs>"Transporte Subcontratado PAGBEM"</xObs>
</compl>
I'm trying to set up a query in which I can tabulate the data within the column. For example:
> cCt-----|CFOP----|cUF----|XObs
> 00040034|5353 |10 |"Transporte Subcontratado PAGBEM"
Of the searches I did, I saw that the CROSS APPLY function exists and I tried to run this query but I could not find the error
SELECT
a.ID_Reg,
ide.value('(./cUF)[1]', 'nvarchar(max)') as UF
FROM
TB_CTR_CTE_XML a
CROSS APPLY [XML].nodes('/cteProc/CTe/infCte/ide') AS Cte(ide)
WHERE a.ID_Reg=1
GO