Hi Lars,
Thanks for your response. Actually it's because a weird behavior of SAP HANA Database and window functions.
If I use ROW_NUMBER() OVER() in a select statement and use the row_number in a order by, the ordination occurs just fine inside the DEBUG. But when I run the very same procedure from the hdb console or XS, the ordination doesn't behave the same way:
Result from DEBUG:
Result from Console:
Talking with some SAP COIL colleagues, they told me it's because SAP HANA optimize the execution and this optimization must be delaying the ROW_NUMBER calculation to the end of execution. So, to avoid that, I've used SEQUENCES instead of ROW_NUMBER.
The problem is, to avoid the sequence to cycle in the middle of the procedure execution, I need to set it to 0 every night.. If we had temporary sequences, I could avoid doing this job of resetting it every night..

