Solved

SQL and dates

Posted on 1998-07-21
8
150 Views
Last Modified: 2010-04-04
Hi All,

I have a question relating to SQL and dates.  I have a database which contains a number of items.  Each time the program is executed, the database is checked to see if an item will be out of date within the next 21 days. The problem that I am having is this:  the query is not returning any items which exceed the date given.

Here is basically what I am doing:


SQL Statement (within the query):

Select * from ALL_ITEMS
where :ThisDate > Items_Date


the :ThisDate parameter is typed as a DateTime, as is the Items_Date


The procedure I am using to check these items is:

Procedure TMain.CheckDates;
Var Check_Date: TDateTime;

begin
   Check_Date := DATE + 21;  
   ItemQuery.Active := False;
   ItemQuery.ParamByName('ThisDate').asDataTime := ChecK_Date;
   ItemQuery.Active := True;
End;

Ok, from this, I get no records in the query at all.

Any ideas at all.  The program is in very early development stages, therefore, I am quite happy to change anything to get this thing working properly!

Thanks for any help you can provide.

Stuart.

If you have any examples, please forward them to jonstu@acay.com.au if possible.

OH!  And as a last second thought, any ideas how to make a Paradox database use full dates??  ie DD/MM/YYYY??.
0
Comment
Question by:Stuart_Johnson
8 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 1358322
What type of database do you use?

It is better to use Open and close:

ItemQuery.Close;
ItemQuery.ParamByName('THISDATE').AsDateTime := Check_Date;
ItemQuery.Open;

But your example should work as well.

How did you check if the Query returns data?

To make an easy check:
Add a TDataSource and set its DataSet property to ItemQuery
Add a DBGrid and set its DataSource property to the DataSource you just added.

If the Query is opened the data should automatically appear in the DBGrid.

Regards Jacco
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1358323
Hi Jacco,

Thats basically how I am doing it now.  I just dont get any data.  I'll keep trying.  Thanks for the comment.  Any more suggestions??

Stu
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1358324
Edited text of question
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 3

Expert Comment

by:vladika
ID: 1358325
Try this
just interchange :ThisDate and Items_Date as

select * from ALL_ITEMS  where Items_Date<:ThisDate

0
 
LVL 2

Expert Comment

by:kjteng
ID: 1358326
I have tried your code. It works fine on my pc.(after changing   ItemQuery.ParamByName('ThisDate').asDataTime to
  ItemQuery.ParamByName('ThisDate').asDatETime)

May be there is really no record dated after 21 from today?
Or may be what you actually want is the result for
   :ThisDate < Items_Date

"to make a Paradox database use full dates"
1. changes the short date format in your Windows Control Panel International dialog box.
 OR
2. put the following line in you program:
     shortDateformat:= 'dd/mm/yyyy';

Hope this help


0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1358327
kjteng,

Can you please repost this as an answer for me.  I'll test this once I get home.  I think I have made a mistake :)  I didnt realise that  you could use the ShortDateFormat though.  Thanks for pointing that out.

Stuart.
0
 
LVL 2

Accepted Solution

by:
kjteng earned 100 total points
ID: 1358328

     changing   ItemQuery.ParamByName('ThisDate').asDataTime to
       ItemQuery.ParamByName('ThisDate').asDatETime)

     May be there is really no record dated after 21 from today?
     Or may be what you actually want is the result for
        :ThisDate < Items_Date

     "to make a Paradox database use full dates"
     1. changes the short date format in your Windows Control Panel International
     dialog box.
      OR
     2. put the following line in you program:
          shortDateformat:= 'dd/mm/yyyy';

     Hope this help
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1358329
Hi kjteng,

OK, I have it working now, thanks very much.  That ShortDateFormat constant would be very handy if it was documented :)  I couldnt find anything in any of the help files or examples relating to it at all.

The program is working just fine.  Thank you.  The points are well earnt!

Stuart.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

808 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