Como consultar valores de nós xml?
Eu tenho uma tabela que contém uma coluna XML:
CREATE TABLE Batches(
BatchID int,
RawXml xml
)
O xml contém itens como:
<GrobReportXmlFileXmlFile>
<GrobReport>
<ReportHeader>
<OrganizationReportReferenceIdentifier>1</OrganizationReportReferenceIdentifier>
<OrganizationNumber>4</OrganizationNumber>
</ReportHeader>
</GrobReport>
<GrobReport>
<ReportHeader>
<OrganizationReportReferenceIdentifier>2</OrganizationReportReferenceIdentifier>
<OrganizationNumber>4</OrganizationNumber>
</ReportHeader>
</GrobReport>
<GrobReport>
<ReportHeader>
<OrganizationReportReferenceIdentifier>3</OrganizationReportReferenceIdentifier>
<OrganizationNumber>4</OrganizationNumber>
</ReportHeader>
</GrobReport>
<GrobReport>
<ReportHeader>
<OrganizationReportReferenceIdentifier>4</OrganizationReportReferenceIdentifier>
<OrganizationNumber>4</OrganizationNumber>
</ReportHeader>
</GrobReport>
O que eu quero é gerar um conjunto que contenha:
OrganizationReportReferenceNumber OrganizationNumber
================================= ==================
1 4
2 4
3 4
4 4
eu tentei:
SELECT
foo.value('/ReportHeader/OrganizationReportReferenceIdentifier') AS ReportIdentifierNumber,
foo.value('/ReportHeader/OrganizationNumber') AS OrginazationNumber
FROM CDRBatches.RawXML.query('/GrobReportXmlFileXmlFile/GrobReport/ReportHeader') foo
mas isso não funciona. eu tentei:
SELECT
foo.value('/ReportHeader/OrganizationReportReferenceIdentifier') AS ReportIdentifierNumber,
foo.value('/ReportHeader/OrganizationNumber') AS OrginazationNumber
FROM RawXML.nodes('/GrobReportXmlFileXmlFile/GrobReport/ReportHeader') bar(foo)
Mas isso não funciona. oXPath expressão
/GrobReportXmlFileXmlFile/GrobReport/ReportHeader
está correto; em qualquer outro sistema xml ele retorna:
<ReportHeader>
<OrganizationReportReferenceIdentifier>1</OrganizationReportReferenceIdentifier>
<OrganizationNumber>4</OrganizationNumber>
</ReportHeader>
<ReportHeader>
<OrganizationReportReferenceIdentifier>2</OrganizationReportReferenceIdentifier>
<OrganizationNumber>4</OrganizationNumber>
</ReportHeader>
<ReportHeader>
<OrganizationReportReferenceIdentifier>3</OrganizationReportReferenceIdentifier>
<OrganizationNumber>4</OrganizationNumber>
</ReportHeader>
<ReportHeader>
<OrganizationReportReferenceIdentifier>4</OrganizationReportReferenceIdentifier>
<OrganizationNumber>4</OrganizationNumber>
</ReportHeader>
Então, é óbvio a partir das minhas perguntas que eugostar ver. Depois de ler uma dúzia de perguntas e respostas sobre o Stackover, não estou mais perto de resolver o problema.