Android Question SQL Order + Where

parijs

Active Member
Licensed User
Longtime User
What am I doing wrong ?

B4X:
oRst = SQL.ExecQuery2("SELECT * FROM Bustrip ORDER BY sort Asc WHERE bus = ?", Array As String (Main.find))
 

parijs

Active Member
Licensed User
Longtime User
Oke but whats wrong now? ;)

B4X:
oRst = SQL.ExecQuery2("SELECT * FROM Bustrip WHERE bus = ?", Array As String (Main.find) ORDER BY sort Asc)
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Oke but whats wrong now? ;)

B4X:
oRst = SQL.ExecQuery2("SELECT * FROM Bustrip WHERE bus = ?", Array As String (Main.find) ORDER BY sort Asc)
B4X:
oRst = SQL.ExecQuery2("SELECT * FROM Bustrip WHERE bus = ? ORDER BY sort Asc", ArrayAsString (Main.find) )
By the way, [sort] is a field? If not, place the field you want instead of it.
 
Upvote 0

parijs

Active Member
Licensed User
Longtime User
Thanks MC

Yes sort is a field
Now its order like 1,10,11 .....2,20
Is there a solution?
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hi, if bustrip is a string then the sort order is correct, if bustrip is always a number then define it as a int/long etc.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
parijs says: I changed it to int and works
Please note that you did not have to change the field data type from TEXT to INTEGER to get the proper sort.
If you have a field named Sort that is of TEXT type in a table, but contains all integers, you do not have to change the field data type in the table to INTEGER. You can always sort using the CAST function like this: ORDER BY CAST(Sort AS INTEGER). The records will be sorted properly.
 
Upvote 0

Similar Threads

Top