PDA

View Full Version : SQLite.QueryToTable(db, "SELECT SUM.....);


sside
10-13-2004, 09:15 AM
Hello everybody

I can't get the sum from;
----------------------------------------------------------------------
resSum = SQLite.QueryToTable(db, "SELECT SUM(Age) FROM Contacts");
----------------------------------------------------------------------
I think the query is supposed to return a single value yet it returns a table;

resSum.ColumnNames
resSum.Rows
resSum.Data
resSum.Columns

If i have to insert the sum into a input object how would it be?

----------------------------------------------------------------------
Input.SetText("Input1", resSum...);
----------------------------------------------------------------------

Any idea would be appreciated

Thank you

Sside

TJ_Tigger
10-13-2004, 11:06 AM
Hello everybody

I can't get the sum from;
----------------------------------------------------------------------
resSum = SQLite.QueryToTable(db, "SELECT SUM(Age) FROM Contacts");
----------------------------------------------------------------------
I think the query is supposed to return a single value yet it returns a table;

resSum.ColumnNames
resSum.Rows
resSum.Data
resSum.Columns

If i have to insert the sum into a input object how would it be?

----------------------------------------------------------------------
Input.SetText("Input1", resSum...);
----------------------------------------------------------------------

Any idea would be appreciated

Thank you

Sside

the SQLite.QueryToTable will always return a table for you to use. My understanding is that you need to identify the returned value, in this case if there is only one value you should be able to get the returned valye like this.


Input.SetText("Input1", resSum.Data[1]["sum(age)"]


Give that a shot

Worm
10-13-2004, 12:17 PM
Try this:


tblSum = SQLite.QueryToTable(db, "SELECT SUM(Age) as Total FROM Contacts");
if tblSum then
Input.SetText("Input1", tblSum[1].Total);
else
Input.SetText("Input1", "0");
end

sside
10-13-2004, 02:58 PM
Tigg, Worm thank you for your time.

Tigg
It works. I understand what you're saying. I agree. I had troubles understanding this (see in red);
---------------------------------------------------------------------
Input.SetText("Input1", resSum.Data[1]["sum(age)"]
---------------------------------------------------------------------
Thanks for the help Tigg.


Worm
I undertstand from your code is Column Name Alias (SELECT column AS column_alias FROM table). It gives me a error. I tried to change smth but no luck. I think i'm doing smth wrong here. Nevertheless i appreciate it.
Thanks for the help Worm


Sside