1. Jonathan Ashwell
  2. Valentina Database ADK
  3. Donnerstag, Januar 25 2024, 03:39 PM
  4.  Abonnieren via E-Mail
Hi,

I need to order a cursor so the result is the same as in a sorted listbox (which can be sorted many different ways).

The solution I found online was to use a CASE statement with ORDER BY. Such as

select * from table
order by (
case id
when 3 then 0
when 1 then 1
when 4 then 2
when 2 then 3
end
)

But this simple example doesn't work (the list contains only one item)

select * from thetable where id in (1) order by case id when 1 then 0 end

What is the correct way to create an arbitrary sort order?
Kommentar
There are no comments made yet.
Ivan Smahin Akzeptierte Antwort
Hi,

As a workaround, you may do something like this one:


select *, (case id
when 3 then 0
when 1 then 1
when 4 then 2
when 2 then 3
end) as f2
from t1
order by f2
Kommentar
There are no comments made yet.
Ivan Smahin Akzeptierte Antwort
Or you may have it as a calculated field (method), and "order by" that field without mention it in the select list
Kommentar
There are no comments made yet.
Jonathan Ashwell Akzeptierte Antwort
Thank you very much, Ivan. I'll try your solutions and be back if I have more questions.
Kommentar
There are no comments made yet.
  • Seite :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Categories

Announcements & News
  1. 0 subcategories
Valentina Studio
  1. 2 subcategories
Valentina Server
  1. 4 subcategories
Valentina Database ADK
  1. 0 subcategories
Valentina Reports ADK
  1. 0 subcategories
Other Discussions
  1. 2 subcategories
BETA Testing
  1. 0 subcategories
Education & Research
  1. 0 subcategories