Advanced Query Incorrect Order

Advanced Query Incorrect Order

I have a Advanced query that is giving me the results in a order i wasn't expecting. I caught with SQL profiler the exec call and run it on sql server. if i test the advance query the order of the results is incorrect but if i run in sql server the exec call i caught with sql profiler the order comes right. 

Has anyone came across this situation?
Hi Marcelo,

Why don't you just add the ORDER BY to the query?
Yes i can have but i would like to know why this happen. I already had order by but that don't decide the order of this 2 records. When this happen Sql server orders by the key but looks like Outsystems doesn't.
OutSystems doesn't change the order in which the results are returned from the database. Either the DBMS is returning different orders or you are sorting the results in your code...
"Thou shalt not trust thy order of results from thy database, unless thou has spcified an ORDER BY clause" is one of the things that often confuses folks.

Databases often appear to order results a particular way, and often they do. But the SQL spec is clear that there is never a guarantee of result ordering unless you give an ORDER BY. If you haven't specified an ORDER BY, you cannot count on those results coming in any particular order.