Query returns nothing

Asked

Viewed 57 times

-1

I’m making an application on android using sqlite but I’m not able to return anything with these Where statments.

I have the following table:

id day month valu1 valu2

and the following cursor:

resultado = db.rawQuery(
       String.format("SELECT * FROM %s 
                      WHERE ((%s>=15 AND %s=%d-1) AND (%s<=14 AND %s=%d))", 
                      NomeTabela, Coluna2, Coluna3, mes, Coluna2, Coluna3, mes),null);

that is to say:

select * from NomeTabela where ((dia>=15 and mes=valor-1) and (dia<=14 and mes=valor))

I’m doing something wrong?

  • 1

    Without knowing which values exist in the table and which should return, we cannot say what is wrong.

  • In fact, as already mentioned, it shows us the data of the table, so that it is possible to understand what may be happening.

1 answer

2

The problem is in your query filter:

where ((dia>=15 and mes=valor-1) and (dia<=14 and mes=valor))

Note that you have placed 2 conflicting conditions on the Where label: mes=value-1 and mes=value. Month can never assume both values, so your query will never return results. If you want the query to return results if they fit the first parent condition OR the other one, the condition should be:

where ((dia>=15 and mes=valor-1) or (dia<=14 and mes=valor))

I hope I’ve helped :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.