2

I have an xml message like this

<Body>
   <test>
       <element>2</element>
       <element>6</element>
       <element>1</element>
   </test>
</Body>

and i want to select the element with the lowest number

something like this

SET data[] = SELECT e FROM Output.Body.test.element[] AS e ORDER BY e.element;

I would have done this if the "ORDER BY" is supported in esql select but it is not, So is there any other way to do something like this?

I know the sql statements can be supported if i used PASSTHRU statement which passes the statement to the DBMS directly, but i am not using DBMS here, i am selecting from xml message.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Kingo Mostafa
  • 357
  • 5
  • 21
  • I'm afraid you will need to do the sorting yourself, either implement it in ESQL, or use some Java library. – Attila Repasi Sep 11 '16 at 16:50
  • Given the lack of ORDER BY support, you'll need to iterate through the list and select the element with the lowest number, as Attila wrote. – Andre Vieira Oct 12 '16 at 08:55

1 Answers1

2

With the following link you can write a Quick Sort procedure to order your list. Then, you just have take the first element of the list.

Source: http://www.mqseries.net/phpBB2/viewtopic.php?p=273722#27372

(I only posted a link because the procedure code is pretty huge and could be updated by his creator)

VincentS
  • 602
  • 1
  • 10
  • 24