I need to sort a query like the example below, where, the searched text is 'un', first after the items that start with 'un'. This is what I need, order the output of the query, so that the items that begin with the text are the first of the result, but without eliminating the others.
Using this StackOverflow response in English: link
I created a SQLite query like this:
SELECT ProDescricao FROM ProdutosDB
where ProDescricao like '%un%'
ORDER BY CASE WHEN ProDescricao like 'un %' THEN 0
WHEN ProDescricao like 'un%' THEN 1
WHEN ProDescricao like '%un%' THEN 2
ELSE 3
END, ProDescricao;
Output example:
28 |UNIAO SOLD 40--
29 |UNIAO SOLD 50--
30 |UNIAO SOLD 60--
35 |ADAPT UNIVERSAL
44 |ADESIVO JUNTA 3M
48 |ALIC MINI 4,5 UN
34 |ACESS WC JUNIOR
My question is, how to do this, with parameter? Calling the query by Android using SQLiteDatabase Query?
Note that the parameter would always be the same:
SELECT ProDescricao FROM ProdutosDB
where ProDescricao like '%'+@busca+'%'
ORDER BY CASE WHEN ProDescricao like ''+@busca+' %' THEN 0
WHEN ProDescricao like ''+@busca+'%' THEN 1
WHEN ProDescricao like '%'+@busca+'%' THEN 2
ELSE 3
END, ProDescricao;
Would it be something like this? Is it correct to use SQLiteDatabase Query or should I use some other form?
Thanks in advance