Board index » delphi » Problem with Query (select sum(*) ...)

Problem with Query (select sum(*) ...)

I figured it out. Sorry. The problem was that the database column had
not been populated. i.e. Every record had NULL in the number field. The
result returned was NULL instead of 0 and printed nothing on the screen.
So... I thought it was not working. When I filled in the field for
something else, the results magically appeared.

Thanks

Abel

 

Re:Problem with Query (select sum(*) ...)


I have a query from wich I want to return the value of the sum of a

Quote
column. I wrote:

query.close;
query.SQL.clear;
query.SQL.Add('select sum(table.number) from table.dbf');
query.ExecSQL;

but what contains the result? How can I retrieve the information into a
variable? Pleas help.

Abel Mireles

Re:Problem with Query (select sum(*) ...)


Quote
Abel Mireles wrote:

> I have a query from wich I want to return the value of the sum of a
> column.

Query.Open     - returns a result set
Query.ExecSQL  - does not return a result set

See (D1) Database Application Developer's Guide ch.5 - "Executing a
query".

Aage J.

Re:Problem with Query (select sum(*) ...)


Quote
Abel Mireles wrote:

> I have a query from wich I want to return the value of the sum of a
> column. I wrote:

> query.close;
> query.SQL.clear;
> query.SQL.Add('select sum(table.number) from table.dbf');
> query.ExecSQL;

> but what contains the result? How can I retrieve the information into a
> variable? Pleas help.

> Abel Mireles

Hi Abel,

Note that ExecSQL is only used when your application does not need a
result set back from your query i.e.: Update, Insert, Delete.

In the case of a select statement, you just need to open your query.
 query.close;
 query.SQL.clear;
 query.SQL.Add('select sum(table.number) from table.dbf');
 query.Open;

regards /Bernard

Other Threads