android - How to sum a varchar column? -


i tried following code irrelevant values on display. noticed because of varchar column tx_amount. how change code sum varchar column?

string[] columns = {vivzhelper.uid, helper.tx_name,  "sum("+helper.tx_amount+") "+helper.tx_amount, helper.tx_date };  cursor c = db.query(vivzhelper.tx_table, columns, helper.tx_id + "='" + name  + "' , " + helper.tx_date + " between '" + datefrom.from_date + "' , '"   + dateto.to_date + "  ' ",null,helper.tx_name, null, null); 

use cast

select cast('1.11' decimal)

source: http://www.sqlite.org/lang_expr.html#castexpr

example:

create table test     (`id` int, `productname` varchar(7), `amount` varchar(10)) ;  insert test     (`id`, `productname`, `amount`) values     (1, 'foo', '1.1'),     (2, 'bar', '1.1'),     (3, 'baz', '1.1') ;  select   sum(cast(amount decimal))   test  ; 

on case:

string[] columns = {vivzhelper.uid, helper.tx_name,      "sum(cast("+helper.tx_amount+" decimal)) "+helper.tx_amount, helper.tx_date }; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -