Hi i have the current XML:
<?xml version="1.0" encoding="utf-8"?>
<tcpos-export>
<transactions>
<transaction>
<code>1</code>
<description>MAXI MERCADO SELECTO</description>
</shop>
<code>2</code>
<description>MAÑANITA PANADERIA</description>
</till>
<cashier>
<code>2004</code>
<description>NELSON PANADERIA</description>
<first-name>NELSON PANADERIA</first-name>
</cashier>
<trans-item type="article">
<hash-code>832129</hash-code>
<code>30237</code>
<quantity>1</quantity>
<unit-price>0.50</unit-price>
<total-price>0.50</total-price>
</trans-item>
<payment type="cash">
<code>01</code>
<description>Efectivo</description>
<description-translations />
<amount>0.50</amount>
<prepayment>false</prepayment>
<signature-required>false</signature-required>
<payment-timestamp>18.08.2021 06:51:27</payment-timestamp>
<cash-change>4.50</cash-change>
<cash-given>5.00</cash-given>
</payment>
with this xquery sql 2019:
--procesar articulos del dia de venta
SELECT
trans.value('(shop/description/text())[1]','varchar(100)') tienda,
trans.value('(till/code/text())[1]','varchar(100)') caja,
trans.value('(cashier/code/text())[1]','varchar(100)') cajero,
trans.value('(beginning-timestamp/text())[1]','varchar(100)') fecha,
trans.value('(trans-num/text())[1]','varchar(100)') transaccion,
item.value('(code/text())[1]','varchar(100)') itemcode,
item.value('(description/text())[1]','varchar(100)') description,
item.value('(hash-code/text())[1]','int') hashcode
FROM [dbo].[XmlImport] xi
CROSS APPLY xi.[LoadedXML].nodes('tcpos-export/transactions/transaction') x1(trans)
CROSS APPLY x1.trans.nodes('trans-item[
hash-code/text() and
not( unit-price[contains(text()[1], "-")] ) and
not( taxable-amount[contains(text()[1], "-")] ) and
not( delete-operator-id/text() )
]') x2(item)
CROSS APPLY (VALUES (
item.value('(quantity/text())[1]','numeric(10,3)'),
item.value('(weight/text())[1]','numeric(10,3)'),
item.value('(vat-code/text())[1]','varchar(100)')
) ) v(quantity, weight, vatcode)
ORDER BY hashcode;
im already getting those columns correctly from transactions node example cashier, till. In adition im getting info from node. But, im confused in how i can get info from the next node
<payment type="cash">
<code>01</code>
<description>Efectivo</description>
<description-translations />
i would like to get code and description
i tried the following:
adding this as additional cross apply
CROSS APPLY xi.[LoadedXML].nodes('tcpos-export/transactions/transaction') x3(payments)
CROSS APPLY x3.payments.nodes('payment[
code/text()
]') x4(payment)
and in select at the end:
payment.value('(code/text())[1]','varchar(100)')
but when i run the query it stays running and running, and got freezed. I dont know what else i can do.
Please give me some tips.
thank you