Solved

How do I select information between 2 dates in delphi access  mdb

Posted on 2008-06-11
6
2,021 Views
Last Modified: 2008-07-01
I have the following SQL
I am adding to delphi codes this query (db is a mdb-access file)

Select SUM(Hours)
From Empolyee
Where (name = 'name') And (date >=#01-06-2008#  and date <= #04-06-2008#)

This query is not turning anything but it is just making the sum for the all data's belong to the name.
So the date selection is not working.

Any idea why?
0
Comment
Question by:Nayel
6 Comments
 

Author Comment

by:Nayel
ID: 21758926
By the way.

If I do it (date >=#2008/06/01 #  and date <= #2008/06/04#)
then I get the results. But I need to add it from delphi.

sql.add('Select ...')
sql.add('From ....')
sql.add('Where ??????????)
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 21759258
selection from last 7 days :


sql.Add('WHERE date >= :date1 and date <= :date2');

sql.prepare;

sql.parambyName('date1').AsDateTime := Now - 7;

sql.ParamByName('date2').AsDateTime := Now;

sql.Open;

Open in new window

0
 

Author Comment

by:Nayel
ID: 21759277


Problem not solved. This will not run in delphi. And my date comes from datetime picker
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 100

Expert Comment

by:mlmcc
ID: 21761298
Can you give the full select/filter statement.

You should be able to use something like
'date >= ' &  StartDAtePicker.Date & ' and date <= ' & enddatepicker.date

mlmcc
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 21761760
Go into MS Access and build your query in SQL form there. When that works, then go into delphi and build it.
0
 
LVL 4

Accepted Solution

by:
spk2000ar earned 50 total points
ID: 21880741
You can do something like this:


s := shortdateformat;

shortdateformat := "aaaa/mm/dd";

sql.add('Select SUM(Hours)')

sql.add('From Empolyee')

sql.add('Where (name = "name") And (date BETWEEN ' + QuotedStr(DateToStr(DateTimePicker1.Date)) + ' and ' + QuotedStr(DateToStr(DateTimePicker2.Date)) + '))';

shortdateformat := s;

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python multiple IF statements 4 75
Reconfigure Delphi Install? 2 45
Problem to page 4 69
How to create virtual printer while installing my application 5 19
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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

947 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now