Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A SQL Select formatting problem 1

Status
Not open for further replies.

BillKilgore

Programmer
Mar 17, 2002
60
US
Hello,

I've been trying to get a SELECT statement addressing an MS Access 2000 database.

This is the code as it is currently failing;

begin
close;
SQL.clear;
SQL.Add('SELECT * FROM Logs
WHERE Specie = '+ebSpecie.Text'
AND ProcessDate = '+ebDate.Text);
Active := True;
open;
LogRecd.log_number := FieldByName('LogNumber').Value;
LogRecd.specie := FieldByName('Specie').AsString;
.
.
.

I've tried several variants such as;

SQL.Add('SELECT * FROM Logs
WHERE Specie = '+QuotedStr(ebSpecie.Text)'
AND ProcessDate = '+QuotedStr(ebDate.Text));

which didn't work and one that did shown below;

SQL.Add('SELECT * FROM Logs
WHERE Specie = ''Pine''
AND ProcessDate = ''3/7/07');

(The examples shown are stacked to conform to this format. The actual code is all in one line)

Switching out the constants 'Pine' and '3/7/07' results in error message 190, 'Missing operator or semicolon.'

At first I though the problem was a matter of quotes but now I think the problem is deeper. Having to do with the presence of variables.

Any help would be greatly appreciated. Thank you.

Bill Kilgore

 
you need to use a parameter, refer to the help for more info but heres a rundown of how its done

Code:
Close;
SQL.Clear;
SQL.Add('SELECT * FROM Logs WHERE Specie =:specieparam AND ProcessDate :=processparam');
ParamByName('specieparam').Value := ebSpecie.Text;
ParamByName('processparam').Value := ebDate.Text;
Open;


Aaron
 
aaronjme,

Thank you for your timely advise. I was unaware of the ParamByName option but I thought it didn't like the variables as I was using them.

Bill Kilgore
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top