Board index » delphi » MS Access Date SQL query problem

MS Access Date SQL query problem


2004-10-16 05:05:02 AM
delphi199
I am converting an existing MS SQL 2000 program to work * also * with Access
Jet database. Essentially I am providing both SQL databases and Jet
databases and the users can decide based on what he/she has which database
they want to use with my client program. This statement worked fine in MS
SQL:
FiltCrit := 'select * from Schedule where SCH_ENDTIME < ' +
QuotedStr(DateToStr(Date));
FiltCrit := FiltCrit + ' order by SCH_STARTTIME';
ScheduleDB.CommandText := FiltCrit;
When the same query is used with the Microsoft.Jet.OLEDB.4.0 provider I get
an error message that states the criteria is not acceptable. I changed it to
the following which Jet accepted:
FiltCrit := 'select * from Schedule where SCH_ENDTIME < ' + DateToStr(Date);
FiltCrit := FiltCrit + ' order by SCH_STARTTIME';
ScheduleDB.CommandText := FiltCrit;
The trouble is that while it is apparently acceptable it produces no results
even though the table has data that meets the criteria above to display.
I tried this as well:
FiltCrit := 'select * from Schedule where SCH_ENDTIME < #' + DateToStr(Date)
+ '#';
FiltCrit := FiltCrit + ' order by SCH_STARTTIME';
ScheduleDB.CommandText := FiltCrit;
This worked but will not work in MS SQL program and the program must be able
to service both providers.
As an experiment I also tried to set the options (under Tables/queries) for
the Jet database to be compatible with ANSI92 SQL Server syntax but still
didn't work.
Being relatively new to MS Access it probable I am missing something obvious
here but so far it eludes me.
Any help would be appreciated. I need the syntax to be acceptable to BOTH MS
SQL Serevr and MS Access (Jet). for dates.
BTW SCH_ENDTIME is a date/time field.
Regards;
Bob Dalton
 
 

Re:MS Access Date SQL query problem

Brian;
My sincere thanks for your help!
Regards;
Bob Dalton
"Brian Bushay TeamB" <XXXX@XXXXX.COM>writes
Quote

>Being relatively new to MS Access it probable I am missing something
>obvious
>here but so far it eludes me.
Not really Jet SQL is just weird




>Any help would be appreciated. I need the syntax to be acceptable to BOTH
>MS
>SQL Serevr and MS Access (Jet). for dates.
You can use a parameter

FiltCrit := 'select * from Schedule where SCH_ENDTIME < :dateParam ';
FiltCrit := FiltCrit + ' order by SCH_STARTTIME';
ScheduleDB.CommandText := FiltCrit;

Then before you open the query set the parameter
ScheduleDB.Parameters.ParambyName('dateParam').value := Date;
--
Brian Bushay (TeamB)
XXXX@XXXXX.COM
 

Re:MS Access Date SQL query problem

Hello !
Just in case if you will again use constants <g>. You
can use escape sequences - {d 'value'}. It will be
expanded into appropriate RDBMS syntax by OLE DB
provider.
Regards,
Dmitry
--
Dmitry Arefiev, gs-soft Company, community.gs-soft.com
SAPx - Delphi to SAP R/3 direct access
Saphir - SAP R/3 metadata on your fingertips
MetaBase - ERWIN model in Delphi applications
NCOCI8 - Freeware Delphi to ORACLE direct access
Bob Dalton writes:
Quote
Brian;

My sincere thanks for your help!

Regards;

Bob Dalton

"Brian Bushay TeamB" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>
>>Being relatively new to MS Access it probable I am missing something
>>obvious
>>here but so far it eludes me.
>Not really Jet SQL is just weird
>
>
>
>
>>Any help would be appreciated. I need the syntax to be acceptable to BOTH
>>MS
>>SQL Serevr and MS Access (Jet). for dates.
>You can use a parameter
>
>FiltCrit := 'select * from Schedule where SCH_ENDTIME < :dateParam ';
>FiltCrit := FiltCrit + ' order by SCH_STARTTIME';
>ScheduleDB.CommandText := FiltCrit;
>
>Then before you open the query set the parameter
>ScheduleDB.Parameters.ParambyName('dateParam').value := Date;
>--
>Brian Bushay (TeamB)
>XXXX@XXXXX.COM
 

Re:MS Access Date SQL query problem

Thank you for the tip!
Rgeards;
Bob Dalton
"Dmitry Arefiev [gs-soft.ru]" <XXXX@XXXXX.COM>writes
Quote
Hello !

Just in case if you will again use constants <g>. You
can use escape sequences - {d 'value'}. It will be
expanded into appropriate RDBMS syntax by OLE DB
provider.

Regards,
Dmitry

--
Dmitry Arefiev, gs-soft Company, community.gs-soft.com

SAPx - Delphi to SAP R/3 direct access
Saphir - SAP R/3 metadata on your fingertips
MetaBase - ERWIN model in Delphi applications
NCOCI8 - Freeware Delphi to ORACLE direct access

Bob Dalton writes:
>Brian;
>
>My sincere thanks for your help!
>
>Regards;
>
>Bob Dalton
>
>"Brian Bushay TeamB" <XXXX@XXXXX.COM>writes
>news:XXXX@XXXXX.COM...
>>
>>>Being relatively new to MS Access it probable I am missing something
>>>obvious
>>>here but so far it eludes me.
>>Not really Jet SQL is just weird
>>
>>
>>
>>
>>>Any help would be appreciated. I need the syntax to be acceptable to
>>>BOTH
>>>MS
>>>SQL Serevr and MS Access (Jet). for dates.
>>You can use a parameter
>>
>>FiltCrit := 'select * from Schedule where SCH_ENDTIME < :dateParam ';
>>FiltCrit := FiltCrit + ' order by SCH_STARTTIME';
>>ScheduleDB.CommandText := FiltCrit;
>>
>>Then before you open the query set the parameter
>>ScheduleDB.Parameters.ParambyName('dateParam').value := Date;
>>--
>>Brian Bushay (TeamB)
>>XXXX@XXXXX.COM