Jednou z metod je použití like
v order by
:
order by (case when name like 'ATUL%' then 1
when name like 'ATU%' then 2
when name like 'AT%' then 3
when name like 'A%' then 4
else 5
end)
Obecnější metodou je také hrubá síla, ale mohla by vypadat nějak takto:
order by (case when left(name, 9) = left('ATUL', 9) then 1
when left(name, 8) = left('ATUL', 8) then 2
when left(name, 7) = left('ATUL', 7) then 3
when left(name, 6) = left('ATUL', 6) then 4
when left(name, 5) = left('ATUL', 5) then 5
when left(name, 4) = left('ATUL', 4) then 6
when left(name, 3) = left('ATUL', 3) then 7
when left(name, 2) = left('ATUL', 2) then 8
when left(name, 1) = left('ATUL', 1) then 9
end)