SQLite Forum

Inconsistency in BETWEEN Query
Login
Hello I am working on an Android SQLite project and can not find a way to get right value, The program takes an input value from the user and searches it in the database, I want to do a query like; if the input value is 3; look through the col_a and col_b if the value is between col_a and col_b prints the col_c value "AA" and col_d value "BB". Like col_a < 3 <col_b prints AA, BB. If col_a < 7 < col_b prints CC, DD.

I am doing a query with the "BETWEEN" but it returns an inconsistent value.

My Table;
ID  |        col_a        |        col_b        |  col_c  |  col_d 
--------------------------------------------------------------------
1   |    4011110000000    |    4011119999999    |   AA    |   BB   
--------------------------------------------------------------------
2   |    4022220000000    |    4022229999999    |   CC    |   DD    
--------------------------------------------------------------------

My Query;
SELECT * FROM my_table WHERE 401111000001 BETWEEN col_a AND col_b

You can see the values in column col_a and col_b is 13 digits long and the query value is 12 digits long. The query returns the item with the ID:1. If I put a 13 digits long value(4011110000001) it also returns the row with ID:1. The problem is 12 digits long value is not in between among the values to be checked.

Android Java Code;
String sql = "SELECT * FROM my_table WHERE ? BETWEEN col_a  AND col_b";
Cursor cursor = db.rawQuery(sql, new String[] {String.valueOf(x)});

if (cursor.moveToNext()) {
    String element1 = cursor.getString(cursor.getColumnIndexOrThrow("col_c"));
    String element2 = cursor.getString(cursor.getColumnIndexOrThrow("col_d"));
    String element3 = cursor.getString(cursor.getColumnIndexOrThrow("ID"));
    cursor.close();
    Log.d(""," " +element1);
    Log.d(""," " +element2);
    Log.d(""," " +element3);
}