Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


SQL open Query error when no data available

Posted on 2003-11-27
Medium Priority
Last Modified: 2010-04-05
Hi all,

I have database that content prices during a year. Im using SQL to find the max and min value in a defined range of date from my database.

my problem is :

for example the file for year 2003 is not completed yet (only until november). When I run the program to find the max and min value for December, the program will be error when the SQL is opened because the prices data is empty.

How to indicate that the SQL doesn't find the value for tha max and min value before I openned the SQL, so that the error wont happened ?

I tried to used : if Query1.IsEmpty = true then ShowMessage(bla bla ..);

 but it doesn't work. The program will also show me the message if I choose another date range... even if the data is available (for example : if I choose March, it will show me the message also)

ps: I dont want to put zero as my defalut value in my database, because later the result for my min. value is always zero where else the price never goes to zero

ok that's all I want to ask... thank youuu ^^
Question by:allie109
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
  • 2
  • 2
  • 2
LVL 27

Expert Comment

ID: 9835602
what database?
how shows your select?

Expert Comment

ID: 9845661
Hi, allie109!

Try to use (query1.recordCount = 0) instead of use query1.IsEmpty...
for example:

procedure Tform1.findExtremePrices;
  with Query1 do
    Sql.text := 'SELECT max(price) AS MAXPRICE FROM priceTable WHERE......
    if (RecordCount = 0) then ShowMessage('bla bla bla')...



Author Comment

ID: 9847520
hi hederglan...
I tried taht way also... but it will give me another error.... because the recordcount cannot be done before the dataset is open..

Kretzschmar.. this is how I open the dataset :

QueryMaxMin.SQL.Add('Select MIN(' + Curr[k] + ') AS ' + Curr[k]+'min, MAX(' + Curr[k]
            + ') AS ' + Curr[k]+'max FROM ' + TableGraph.TableName + ' WHERE DateRec
            BETWEEN "' + DateToStr(FDay[i]) + '" AND "' + DateToStr(LDay[i]) + '"');


the error happened when I oppened the query

It tried to put :
    if QueryMaxMin.IsEmpty = true then showmessage('bla bla...');
but the message will also shown when the database is available

I tried to put :
    if (RecordCount = 0) then ShowMessage('bla bla bla');

it wont work cos' the recordcount cannot be done in a closed dataset

hummm... anyone got the solution...? =s

thank you ^^

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.


Expert Comment

ID: 9849351
Hi again, allie109!

What I'm saying is to use QueryMaxMin.RecordCount = 0 after open the query...
Your code would look like:
if QueryMaxMin.RecordCount = 0 then ShowMessage(bla bla)...

With the dataset opened it will work without problems...


LVL 27

Accepted Solution

kretzschmar earned 120 total points
ID: 9849377
a select with only aggregate-functions is never empty,
but the fieldvalues may be NULL,
which may cause your problem

meikl ;-)


Author Comment

ID: 9854889
Hi Hederglan,

I tried that way too...
if QueryMaxMin.RecordCount = 0 then ShowMessage(bla bla)...

but It give me error just BEFORE the Query open....

humm... how any solution..?? =s

thankssss ^^

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

704 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