Query returns nothing [closed]

-1

I am making an android application with sqlite feature but I am not able to return anything with these where statments .

I have the following table:

  

id day month value1 value2

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:

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

Am I doing something wrong?

    
asked by anonymous 23.08.2016 / 08:20

1 answer

2

The problem is in your query filter:

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

Notice that you placed 2 conflicting conditions in the class where: month = value-1 and month = value . Month can never assume both values, so your query will never return results. If you want the query to return results if they match the first condition OR in the other condition, the condition should be:

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

I hope I have helped:)

    
28.08.2016 / 17:32