Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2003
    Location
    The Netherlands
    Posts
    475

    SQLite.QueryToTable(db, "SELECT SUM.....);

    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

  2. #2
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Quote Originally Posted by sside
    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.

    Code:
    Input.SetText("Input1", resSum.Data[1]["sum(age)"]
    Give that a shot
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  3. #3
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    Try this:

    Code:
    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

  4. #4
    Join Date
    Dec 2003
    Location
    The Netherlands
    Posts
    475
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts