I am new to SQLite and Android. And wanted to calculate SUM of column1 when dates in column2 is selected.I am writing following function while receiving parameters fromDate and toDate in following function:
int tot=0;
SQLiteDatabase db=this.getWritableDatabase();
String query= "SELECT SUM("+ COL_3+ ")" +" AS "+"Total"+" FROM "+TABLE_NAME+ " WHERE "+ COL_4+
" BETWEEN "+ fromDate + " AND "+toDate+" ";
Cursor cursor=db.rawQuery(query,null);
if(cursor.moveToFirst()){
tot=cursor.getInt(0);
}
return tot;
But this is giving tot value zero. What am I doing wrong here. Any help would be much appreciated.
Thanks in advance.
COL_3,TABLE_NAME,fromDate, ...