Solved

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

Posted on 2008-06-11
6
2,046 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to event 3 97
Why can't I create any project with my delphi EXE file? 6 26
Problem to refer to value 8 49
firemonkey keyboard covers the controls 1 26
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…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

777 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