TIP: Click on subject to list as thread! ANSI
echo: delphi
to: THEO LEIJEN
from: YVES VAN HAL
date: 1996-05-21 00:44:00
subject: dynamic SQL

Hello Theo,
 > I have made an application in which i use a query with SQL.
 > I'm using a 'WHERE' claus in that query but it doesn't work as it
 > should!
 > In this 'WHERE' clause, i want to compare a DATE with an inputfield.
 > I tried al sorts of formats for that inputfield but the query doesn't
 > work.
 > Can somebody tell me how to deal with this problem.
 > Thank you
I quickly tried the following:
I created a table named D with one field name DT, which has a date format, in 
it.
Then, on a form I put a DataAccess object and a query object and a TDBGrid. 
In addition I added a TButton called select and an TInput called Edit1.
The SQL property for the query is set to the following TString:
select dt from d where dt = :h_dt
After that, I inspected the Params property of the TQuery object and assigned 
the date type to the h_dt parameter.
To the OnClick event of the select button, I assigned the following code :
begin
  query1.close;
  query1.params[0].asdate:=strtodatetime(Edit1.text);
  query1.open;
end;
This results in the query selecting only those entries from the table having 
their dt column set to the value of Edit1 when clicking the select button. Of 
course, you will have to add some checking before assigning the value to the 
params property. Or, you will have to write a try ... construction to trap 
all errors generated by the query1.open statement.
Hope this helped,
Yves
Belgium
--- FMail 0.92
---------------
* Origin: First there was Oracle, finally we got Delphi (2:292/8014.9)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.