Reputation: 11782
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
Upvotes: 0
Views: 763
Reputation: 181097
Your BETWEEN
syntax 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.
Upvotes: 1