0

i am trying to select some accounts depending on the updating time..

My Table named as account and has columns like createdOn , updatedOn, acountName etc.

Now the date is being stored as string 2012-03-20

How can i make sql query to select diff accounts depending on date.

Here is my code

 public ArrayList<Account> getAllAccountsForReports(Date dateTo, Date dateFrom)
  {
      ArrayList<Account> accounts = new ArrayList<Account>();
      String queryString = "SELECT * FROM MAAccounts WHERE updatedOn = ? BETWEEN updatedOn = ? ORDER BY accountType, accountName";
      Cursor result =  mDb.rawQuery(queryString, new String[]{ dateToDB(dateTo), dateToDB(dateFrom)}); 

Please tell me how can i correct my sql query.

Best Regards

1 Answer 1

1

Your BETWEENsyntax is off, what you want is probably;

SELECT * FROM MAAccounts 
WHERE updatedOn 
  BETWEEN ? AND ?
ORDER BY accountType, accountName

Since you're storing by 'yyyy-MM-dd', between should work well using a string.

I wasn't sure what table name to use since you said it was called account in the question and MAAccounts in the code and the columns are mis-spelled in the question, so of course you need to adapt it to your actual column names.

Sign up to request clarification or add additional context in comments.

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.