• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 129
  • Last Modified:

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;
0
cavalry
Asked:
cavalry
1 Solution
 
BlackManCommented:
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
0
 
MatveyCommented:
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.
0
 
cavalryAuthor Commented:
I think Ive got it sorted now, BUT HOW do I show the result of the Sum calculation in a DBText component ??

Thanks
0
 
ZifNabCommented:
cavalry you can use :

select Sum(Value) as SumOfValue from orders

Now sumOfValue is a fieldname. Can be used as normal fieldname.

Zif.
0
 
kretzschmarCommented:
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
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now