Android Question Get Total(SUM) from column ?

mat_10

New Member
Hi,

I'm new to SQlite in B4A and I'm trying to get the total amount of systollic value after entering values
into that column.

What am I doing wrong here ?

Please help me understand.

Thanks.

Here's the code ....

'declare cursor object
Dim Cursor1 As Cursor

'get sum
Cursor1 = SQL1.ExecQuery("SELECT sum(Systollic) FROM BP")
Cursor1.Position = 0

'display sum
lblResult.Text = Cursor1.GetInt("Systollic")

I get error message -- 'Systollic' does not exist. Available columns: [sum(Systollic)]
 

mat_10

New Member
Hi,

I'm new to SQlite in B4A and I'm trying to get the total amount of systollic value after entering values
into that column.

What am I doing wrong here ?

Please help me understand.

Thanks.

Here's the code ....

'declare cursor object
Dim Cursor1 As Cursor

'get sum
Cursor1 = SQL1.ExecQuery("SELECT sum(Systollic) FROM BP")
Cursor1.Position = 0

'display sum
lblResult.Text = Cursor1.GetInt("Systollic")

I get error message -- 'Systollic' does not exist. Available columns: [sum(Systollic)]

Did you mean ? Cursor1 = SQL1.ExecQuery("SELECT sum(Systollic) as Systollic FROM BP")
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
I get error message -- 'Systollic' does not exist. Available columns: [sum(Systollic)]
if you want that your columns call Systollic the right code is: ...Sum(Systollic) as Systollic ....
Tip read an SQL manual, will be more simple
 
Upvote 0

PdeG

Member
Licensed User
Longtime User
Test for null values,

B4X:
'display sum
 lblResult.Text = SQL1.ExecQuerySingleResult("SELECT SUM(IFNULL(Systollic, 0)) FROM BP ")
 
Upvote 0
Top