Solved

SQL open Query error when no data available

Posted on 2003-11-27
8
226 Views
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 ^^
0
Comment
Question by:allie109
[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
  • 2
  • 2
  • 2
8 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9835602
what database?
how shows your select?
0
 
LVL 1

Expert Comment

by:hederglan
ID: 9845661
Hi, allie109!

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

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

regards!

Hederglan
0
 

Author Comment

by:allie109
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.Close;
QueryMaxMin.SQL.Clear;
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]) + '"');

QueryMaxMin.Open;

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 ^^

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:hederglan
ID: 9849351
Hi again, allie109!

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

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

[]s

Hederglan
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 30 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 ;-)

0
 

Author Comment

by:allie109
ID: 9854889
Hi Hederglan,

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


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

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

thankssss ^^
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month6 days, 1 hour left to enroll

627 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