Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I tried with the following code but get irrelevant values on display.
I noticed that it is because of Varchar column for TX_AMOUNT.
How to change the code to sum that varchar column.


String[] columns = {VivzHelper.UID, helper.TX_NAME, "SUM("+helper.TX_AMOUNT+") AS "+helper.TX_AMOUNT, helper.TX_DATE };
Posted
Comments
Richard Deeming 15-May-15 8:34am    
This is why you don't use string types to store values which aren't strings!

Change your column to a more appropriate type - there are various numeric types to choose from.
S.Rajendran from Coimbatore 16-May-15 3:34am    
As said by you earlier I tried with a NUMERIC type column and when I wanted to get it to variable I got error when the number in the column exceeds 6,2 (with decimal).
String[] columns = { helper.TX_UID, helper.TX_NAME, helper.TX_PARTICULARS, helper.TX_AMOUNT, helper.TX_DATE,helper.TX_CONTRA}; // from tx_table..tested ok
Cursor c = db.query(VivzHelper.TX_TABLE, columns, (helper.TX_ID + "='" + name + "' AND " + helper.TX_DATE + "= '" + td + "'"), null, null, null,null);
gt = 0;
gt_selectedItem_number = 0; // numbers refers to int variable for int column
if (c != null) {
c.moveToFirst();
while (c.isAfterLast() == false) {
String txTotal=null;
String v_uid=(c.getString(0));//tx_id is passed here..not used ofcourse
txTotal = (c.getString(3)); //not ok
Float fl=(c.getFloat(3)); //not ok

How to get , the NUMERIC coulumn TX_AMOUNT to pass to a suitable variable for calculation purposes?

1 solution

In SQL you can CONVERT(DECIMAL(18,2), TX_AMOUNT) for example. Just convert it to the type of number it should be.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900