?
Solved

Difference of Query results using 'Between ...and ...' in SQL Sercer 2000 and Delphi6.0 professional

Posted on 2003-03-20
5
Medium Priority
?
154 Views
Last Modified: 2010-04-04
Hi, all

I want to query the data in a limited period e.g. from 3/2/2003 to 3/21/2003.

I get the desired result in sql sqrver 2000 using the statements as follows

Select *
from tablename
where datacolumn between '3/2/2003' and '3/21/2003'

The query result include the data with the datacolumn in 3/2/2003 and 3/21/2003.

But unfortunately, when I execute the above statement in Delphi6.0 by TQuery like the following

frmData.tsqlInvoice.close;
frmData.tsqlInvoice.unprepare;
frmData.tsqlInvoice.clear;            
frmdata.tsqlInvoice.SQL.add('Select * from tablename');
frmdata.tsqlInvoice.SQL.add('where datacolumn between :begin and :end');
frmdata.tsqlInvoice.Params[0].AsDateTime  := dtpBegin.DateTime ;
frmdata.tsqlInvoice.Params[1].AsDateTime := dtpEnd.datetime;
frmData.tsqlInvoice.Prepare ;
frmData.tsqlInvoice.open;

The result excludes the data with the datacolumn in 3/2/2003. So, in order to get the data with the datacolumn in 3/2/2003 I have to set the begin date as 3/1/2003.

Can you tell me what the problem is and how to get the desired query result in Delphi6.0 professional?

Great thanks

Jason
0
Comment
Question by:jasoncen
[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
5 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 300 total points
ID: 8177145
there may a timefragment
try following change

frmdata.tsqlInvoice.Params[0].AsDateTime  := trunc(dtpBegin.DateTime);
frmdata.tsqlInvoice.Params[1].AsDateTime := trunc(dtpEnd.datetime);

meikl ;-)
0
 
LVL 3

Expert Comment

by:ILE
ID: 8178229
my hint


there may a timefragment
try following change

frmdata.tsqlInvoice.Params[0].AsDateTime  := trunc(dtpBegin.DateTime);
frmdata.tsqlInvoice.Params[1].AsDateTime := trunc(dtpEnd.datetime+1);

if the target colmun is datetime type if not all must be worknig;

ile :))
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8180183
usual most databases storing dates as datetime, ile

;-)
0
 

Expert Comment

by:hetturki
ID: 8216700
Hi
First try it in this way & dont use use the keyworks such as Begin , End as parameters.

frmData.tsqlInvoice.close;
frmData.tsqlInvoice.unprepare;
frmData.tsqlInvoice.clear;            
frmdata.tsqlInvoice.SQL.add('Select * from tablename');
frmdata.tsqlInvoice.SQL.add('where datacolumn between :begin and :end');
frmdata.tsqlInvoice.Parameters.ParaByName('begin').value  := dtpBegin.DateTime ;
frmdata.tsqlInvoice.Parameters.ParaByName('end').value := dtpEnd.datetime;
frmData.tsqlInvoice.open;
0
 

Author Comment

by:jasoncen
ID: 8391857
Hi, kretzschmar

Based on your advice I have successfully solve my problems.

Great thanks!

Jason
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

765 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