Solved

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

Posted on 2008-06-11
6
2,157 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
[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
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
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 101

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

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!

Question has a verified solution.

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

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 …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

688 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