I have a table named TBTASK structure is as follows
PRIID CHARACTER(15) NOT NULL,
BID CHARACTER(10) NOT NULL,
REF CHARACTER(15) NOT NULL,
TIME TIMESTAMP NOT NULL DEFAULT CURRENT TIMESTAMP,
XMLREC XML NOT NULL
XML stored in DB XMLREC column is as follows
<Root><Code>6</Code><Id>4</Id><Number>999</Number></Root>
<Root><Code>6</Code><Id>4</Id><Number>1001</Number></Root>
<Root><Code>6</Code><Id>4</Id><Number>1002</Number></Root>
<Root><Code>6</Code><Id>4</Id><Number>998</Number></Root>
Im using below XQUERY for geeting the data:
XQUERY
let $str:= subsequence((db2-fn:sqlquery( 'SELECT XMLREC FROM LIS.TBTASK WHERE BID=1')
/Root[Code='6']),1,5)
order by $str/Root/Number
return ($str)
but Im not getting the result in sorted order as per NUMBER column(order by is applied on NUMBER.
Could you please help me in this.
This should work:
Note, that you need at least one for statement for order by to be useful. Also, your path ($str/Root/Number) was wrong as $str is already at the Root-Node. Additionally I assumed that you want to sort this in a numerical way and not as strings, so I added an explicit type cast to make it work.