Board index » delphi » SQL Searching date field

SQL Searching date field

I have been trying to write an SQL statement to filter data by a date entry
in a table like so:-

select * from 'TableName'
Where "Invoice Date" = ??/??/??

Eventually I want to place two variable parameters to meet the  search
requirements,(from - to) but for now I am unable to get any data out in the
form of a DB Grid. All I get is a plain row that  suggests the search data
is not being matched to field data.

The table is prepared with Paradox 7 in Delphi2, using the 'Date' field in
the preparation of the table. Now I think that this is the problem, but
being new to the venture of SQL, I am unable to come up with the answer and
would be grateful for any help.

Thanks,
Marcus.

 

Re:SQL Searching date field


Quote
Marcus wrote in message <7tnjoj$7d...@forums.borland.com>...
>I have been trying to write an SQL statement to filter data by a date entry
>in a table like so:-

>select * from 'TableName'
>Where "Invoice Date" = ??/??/??

Use parameters in your TQuery. The SQL Text should be:

select * from TableName
where "Invoice Date" = :invoicedate;

From then on you only need to set the date value in the parameter:

  Query1.Close; // important, must close
  Query1.Params.FieldByName('invoicedate').AsDateTime :=
SomeDateTimeVariable;
  Query1.Open;

--
Wayne Niddery - WinWright Consulting
RADBooks - http://members.home.net/wniddery/
Bill of NO Rights; ARTICLE VIII:  You DON'T have the right to demand that
our children risk their lives in foreign wars to soothe your aching
conscience.

Re:SQL Searching date field


Wayne,

Thank you for your reply I have tried parameters but still keep getting the
error message ' Type Mismatch in Expression, as though the data type 'Date'
in SQL does not match data type 'Date', in the paradox field. If I set the
data type to 'String' you can open the Query but there is no data, again the
field not being recognised.
Grrrr......
I have now pulled out great clumps of hair. I am wondering if there is a
glitch somewhere, but I can not see where.

Quote
> Use parameters in your TQuery. The SQL Text should be:

> select * from TableName
> where "Invoice Date" = :invoicedate;

> From then on you only need to set the date value in the parameter:

>   Query1.Close; // important, must close
>   Query1.Params.FieldByName('invoicedate').AsDateTime :=
> SomeDateTimeVariable;
>   Query1.Open;

I think you will find that ,
Query.Params[0].AsDateTime := "Whatever"
works here better, the [0] being the first parameter called in the Parameter
name definitions listing.

Quote

> --
> Wayne Niddery - WinWright Consulting
> RADBooks - http://members.home.net/wniddery/

Liked the site.
Thanks
Marcus.

Re:SQL Searching date field


Are you using ODBC or BDE native driver ?
If you are using the last, check for the date format at Driver's BDE page.

Re:SQL Searching date field


Quote
> I have been trying to write an SQL statement to filter data by a date entry
> in a table like so:-

> select * from 'TableName'
> Where "Invoice Date" = ??/??/??

I was working with dates over the weekend (even inserting them is a blast!) and
found I had to play with the "date" parameters in the BDE Admin program (system
config->date) and set a couple options in there to force "XX/XX/XXXX"
formatting (or at least XX/XX/XX".  By default, the BDE doesn't force 2 and 4
digits for month, date, year.  Once I changed that stuff, mine started working.

"Delphi's a blast"

Other Threads