Link to home
Start Free TrialLog in
Avatar of cavalry
cavalry

asked on

Help - what's wrong with this query

I keep all sorts of EDB errors when running the following query and I'm at my wits end. Can anyone see or suggest what might be wrong. All I want to do is get the total of the Value field in the orders table. Thanks.

with Query1 do begin
     Close;
     with SQL do begin
       Clear;
       Add ('SELECT Sum (Value) FROM Orders');
       end;
     Open;
     end;
Avatar of BlackMan
BlackMan

The only thing is the use of nested With. Especially in D4, I've seen a few examples where methods are not called in the context of the With, one are counting on. This is of course only true if the method is declared in both of the objects in With statements..
Try to do the same thing without the use of With, the SQL look ok..
One other thing could be if you are tryingto close an query that is not active, I'm not quite sure if that is supported. Otherwise, use If Active Then Close
Try running the query in the Database Desktop. If you get no errors there, then try to be more specific with the error messages you get while running this from your code.
Avatar of cavalry

ASKER

I think Ive got it sorted now, BUT HOW do I show the result of the Sum calculation in a DBText component ??

Thanks
ASKER CERTIFIED SOLUTION
Avatar of ZifNab
ZifNab

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kretzschmar
hi cavalry,

is the dbtext.field connected to a datasource which is pointed to your query, the fieldname is the name of your aggregat-function (in this case SUM(VALUE)).

But the better way is zifs answer

meikl