Solved

SQL and dates

Posted on 1998-07-21
8
153 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
[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
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
Industry Leaders: 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

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!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
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…
Suggested Courses
Course of the Month5 days, 17 hours left to enroll

626 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