Re: Sql Date Question



John,

Just curious, what dates are you using (what does the SQL end up looking
like)?

If it were me, I would use parameters...(at design time)...

Set the TADODataSet.CommandText to

Select
T.MyField1,
T.MyField2
From
dbo.MyTable T
Where
T.AppDate BETWEEN :StartDate AND :EndDate

Select the the Parameters property, notice there are two parameters,
StartDate and EndDate

In Delphi code (code is off the top of my head, so there are probably syntax
errors)

{ex. in a datamodule}
public
function OpenQuery(const StartDate, EndDate :TDateTime) :Boolean;
end;

function TdmMyDataModule.OpenQuery(const StartDate, EndDate :TDateTime)
:Boolean;
begin
with qMyQuery do
begin
try
Parameters.ParamByName('StartDate').Value :=
FormatDateTime('mm/dd/yyyy', StartDate);
Parameters.ParamByName('EndDate').Value :=
FormatDateTime('mm/dd/yyyy 11:59PM', StartDate);
Open();
Result := NOT(IsEmpty);
except
on E:Exception do
begin
Result := False;
{set an error message property, construct/raise a more
description error, etc }
end;
end;
end;
end;

Now the UI...

{Some button click}
begin
if (dmMyDataModule.OpenQuery(DateEdit1.Date, DateEdit2.Date)) then
begin
ShowMessage('Yippee, it worked!');
end
else
begin
ShowMessage(dmMyDataModule.ErrorMsg);
end;
end;


Good luck,
krf

"John" <johnpk1946@xxxxxxxxx> wrote in message
news:4561e905$2@xxxxxxxxxxxxxxxxxxxxxxxxx
Hi
Add('Select * from Table1');
Add('Where APPTDATE >= ' +
QuotedStr(FormatDateTime('mm"/"dd"/"yyyy', FromDate)));
Add(' AND APPTDATE <= ' +
QuotedStr(FormatDateTime('mm"/"dd"/"yyyy', ToDate)));
Add('Order by LeadNo');
The above sql stmt works find if the from & to dates are within the
same
year but not if the years is different. The table will have many yeats on
it.
Something is amiss but I can't figure it out.

Thanks
John




.


Quantcast