Xquery with dynamic Index : i am trying to use Xquery in Sql Server, but i need that the index be dynamic:

This is my query:
<code>
SELECT cast(yourXML as XML).value('(/integracao/item/NumPedido)[1]','VARCHAR(MAX)') NumPedido
FROM #xml
</code>

what i have tried:
<code>
SELECT cast(yourXML as XML).value('(/integracao/item/NumPedido)[sql:variable("@index")]','VARCHAR(MAX)') NumPedido
FROM #xml
</code>

But it returns me the error:
XQuery [#xml.yourXML.value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'

Somebody can help me please?


