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

x
?
Solved

SQL and dates

Posted on 1998-07-21
8
Medium Priority
?
155 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
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!

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

670 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