Solved

SQL and dates

Posted on 1998-07-21
8
151 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

685 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