Hello together,
I'm looking for an easy way to sort my query by ABS values.
Example:
I have an integer column with positive and negative values and urgently need the order in ascending order according to the absolute values .
This is a more complex ObjectManager.Find query that I call in a loop.
ObjectManager.Find<entity>
.something else
.OrderBy( abs( MyIntegerField))
.List;
102
-205
222
321
-456
Is there something simple here?
Thomas
Ok, after a few tries I found a solution.
After the first test it works.
Can it be improved further? Or is it good the way it is?
(If ok, you can mark it as "solution")
.AddOrder( TOrder.Asc( TProjections.Sql<Integer>('abs({MyIntegerField})')))
Best regards, Thomas
wlandgraf
(Wagner Landgraf)
November 6, 2023, 12:15pm
3
Yes, that's a good way to do it.
You could also use SQL function mechanism, and register abs
as a function. More info here:
https://doc.tmssoftware.com/biz/aurelius/guide/queries.html#sqlfunction
But that would be overkill if you just want to use it once like you did.
system
(system)
Closed
November 7, 2023, 12:15pm
4
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.