0

I have a problem for which I am writing one search query to do a search based on Date range which is in a string format. The problem is I am not able to query between two date ranges I specify.

This is my query::

String query = "SELECT DISTINCT * FROM Object WHERE (( TransactionAccount = '" + parameter + "') AND (CAST(Amount AS REAL) BETWEEN " + min_amount + " AND " + max_amount + ") AND Date BETWEEN   Date(2012-01-02)  AND  Date(2014-01-02)  ) ";

querylist = dbConn.Query<Passbook_transaction.Object>(query).ToList<Passbook_transaction.Object>(); ;

But its returning SQLite Exception.

The error seems to be in the "Date" because removing the date querying works.

3
  • What is the exact error message? Commented Feb 14, 2014 at 14:53
  • Date is the name of the function and the name of your column? I can see a conflict here. By the way, are you sure that Date (the function) requires just one parameter without the string quoting? Commented Feb 14, 2014 at 15:02
  • Hi, Now its not returning errors but the querylist size is shown as empty. even though there are transactions between those date range. Commented Feb 15, 2014 at 5:02

2 Answers 2

1

try this, quoting dates:

String query = "SELECT DISTINCT * FROM Object WHERE (( TransactionAccount = '" + parameter + "') AND (CAST(Amount AS REAL) BETWEEN " + min_amount + " AND " + max_amount + ") AND Date BETWEEN   Date('2012-01-02')  AND  Date('2014-01-02')  ) ";
Sign up to request clarification or add additional context in comments.

Comments

1

Sorted out the issue by adding the date in db in format "yyyy-MM-dd HH:mm:ss"(which is accepted by SQLite) and using the query below:

 String query = "SELECT DISTINCT * FROM Object WHERE (( TransactionAccount = '" + parameter + "') AND (CAST(Amount AS REAL) BETWEEN " + min_amount + " AND " + max_amount + ") AND TDate BETWEEN   Date('2014-01-01 19:45:46')  AND  Date('2014-02-01 19:05:43')  ) ";

Thanks all for comments and answers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.