?
Solved

Help - what's wrong with this query

Posted on 1998-11-18
5
Medium Priority
?
126 Views
Last Modified: 2010-04-04
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
Comment
Question by:cavalry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 7

Expert Comment

by:BlackMan
ID: 1347270
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
 
LVL 3

Expert Comment

by:Matvey
ID: 1347271
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
 

Author Comment

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

Thanks
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 40 total points
ID: 1347273
cavalry you can use :

select Sum(Value) as SumOfValue from orders

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

Zif.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1347274
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question