Delphi 7 Syntax error (comma) in ADO query - sql

I'm trying to create a record in a database using a SQL query in Delphi 7. I'm using an ADO Query and I've tried both with and without parameters, but to no avail. The error occurs between ShowMessage 1 and 2.
sName := ledName.Text;
sSurname := ledSurname.Text;
sSchool := ledSchool.Text;
sMotherName := ledMotherName.Text;
sMotherCell := ledMotherCell.Text;
sMotherEmail := ledMotherEmail.Text;
sFatherName := ledFatherName.Text;
sFatherCell := ledFatherCell.Text;
sFatherEmail := ledFatherEmail.Text;
sAddress := ledAddress.Text;
sBirthday := DateToStr(dpcBirthday.Date);
ShowMessage(sBirthday);
case rgpGender.ItemIndex of
0 : cGender := 'M';
1 : cGender := 'F';
end;
iGrade := rgpGrade.ItemIndex - 2;
if chkLeader.Checked = true then
bLeader := True
else
bLeader := False;
with dmData do begin
ShowMessage('1');
qryMain.Active := False;
qryMain.SQL.Text := 'SELECT * FROM Users Where Name = "'+sName+'", Surname = "'+sSurname+'", Birthday = "'+sBirthday+'" ';
qryMain.Open;
if qryMain.RecordCount = 0 then begin
qryMain.Close;
ShowMessage('2');
//qryMain.SQL.Text := 'INSERT INTO Users(Name, Surname, MotherName, FatherName, Gender, Grade, Birthday, School, Address, MotherCell, FatherCell, MotherEmail, FatherEmail, NameTag, Volunteer) VALUES("'+sName+'", "'+sSurname+'", "'+sMotherName+'", "'+sFatherName+'", "'+cGender+'", "'+IntToStr(iGrade)+'", "'+sBirthday+'", "'+sSchool+'", "'+sAddress+'", "'+sMotherCell+'", "'+sFatherCell+'", "'+sMotherEmail+'", "'+sFatherEmail+'", False, "'+BoolToStr(bLeader)+'") ';
qryMain.SQL.Text := 'INSERT INTO Users(Name, Surname, MotherName, FatherName, Gender, Grade, Birthday, School, Address, MotherCell, FatherCell, MotherEmail, FatherEmail, NameTag, Volunteer) ' + 'VALUES(:Name, :Surname, :MotherName, :FatherName, :Gender, :Grade, :Birthday, :School, :Address, :MotherCell, :FatherCell, :MotherEmail, :FatherEmail, False, :Leader) ';
qryMain.Parameters.ParamByName('Name').Value := sName;
qryMain.Parameters.ParamByName('Surname').Value := sSurname;
qryMain.Parameters.ParamByName('MotherName').Value := sMotherName;
qryMain.Parameters.ParamByName('FatherName').Value := sFatherName;
qryMain.Parameters.ParamByName('Gender').Value := cGender;
qryMain.Parameters.ParamByName('Grade').Value := iGrade;
qryMain.Parameters.ParamByName('Birthday').Value := sBirthday;
qryMain.Parameters.ParamByName('School').Value := sSchool;
qryMain.Parameters.ParamByName('Address').Value := sAddress;
qryMain.Parameters.ParamByName('MotherCell').Value := sMotherCell;
qryMain.Parameters.ParamByName('FatherCell').Value := sFatherCell;
qryMain.Parameters.ParamByName('MotherEmail').Value := sMotherEmail;
qryMain.Parameters.ParamByName('FatherEmail').Value := sFatherEmail;
qryMain.Parameters.ParamByName('Leader').Value := bLeader;
ShowMessage('3');
qryMain.ExecSQL;
qryMain.SQL.Text := 'SELECT * FROM Users';
qryMain.Open;
The commented out part was the one way I tried doing this, and it gave this error:
Syntax error (comma) in query expression 'Name="Derp",Surname="Foo",Birthday="1900-01-01"'
The code with parameters gives me this error:
Syntax error (comma) in query expression 'Name="Derp",Surname="Foo",Birthday="1900-01-01"'
Any help would be greatly appreciated!

Now that we can see your real code, your error is clear
'SELECT * FROM Users Where Name = "'+sName+
'", Surname = "'+sSurname+
'", Birthday = "'+sBirthday+'" ';
should use the AND operator to link those conditions :
'SELECT * FROM Users Where Name = "'+sName+
'" AND Surname = "'+sSurname+
'" AND Birthday = "'+sBirthday+'" ';
You should also, naturally, seriously consider parameterizing this query as well.

Related

Oracle Loop by User Name

I found a script that will allow you to End Date a Responsibility by providing the User Name and Responsibility name. I'm trying to figure out how to create this into a loop so that User Name doesn't have to be provided.
Something along the logic of:
if (responsibility exists for user)
end date
else
check next user
Here's the script I've been using to end date via user name:
DECLARE
v_user_name VARCHAR2 (100) := 'PRAJKUMAR';
v_responsibility_name VARCHAR2 (100) := 'Application Developer';
v_application_name VARCHAR2 (100) := NULL;
v_responsibility_key VARCHAR2 (100) := NULL;
v_security_group VARCHAR2 (100) := NULL;
BEGIN
SELECT fa.application_short_name,
fr.responsibility_key,
frg.security_group_key
INTO v_application_name,
v_responsibility_key,
v_security_group
FROM fnd_responsibility fr,
fnd_application fa,
fnd_security_groups frg,
fnd_responsibility_tl frt
WHERE fr.application_id = fa.application_id
AND fr.data_group_id = frg.security_group_id
AND fr.responsibility_id = frt.responsibility_id
AND frt.LANGUAGE = USERENV ('LANG')
AND frt.responsibility_name = v_responsibility_name;
fnd_user_pkg.delresp
( username => v_user_name,
resp_app => v_application_name,
resp_key => v_responsibility_key,
security_group => v_security_group
);
COMMIT;
DBMS_OUTPUT.put_line ( 'Responsiblity '
|| v_responsibility_name
|| ' is removed from the user '
|| v_user_name
|| ' Successfully'
);
END;
/
Reference: https://blogs.oracle.com/prajkumar/end-date-responsibility-for-oracle-fnd-user

Cursor for loop to return output in proper format in oracle stored procedure

I have below procedure in which i want to return the output of variable value brand_name.BRAND_NAME. I am getting the correct output. But i want to return it in proper format. For example right now i am getting the output as
BRAND_NAMES:FNC
BRAND_NAMES:LIDL
But i want to return the output as:
BRAND_NAME: FNC,LIDL
Here is my stored procedure:
FUNCTION BUILD_ALERT_EMAIL_BODY
(
IN_ALERT_LOGS_TIMESTAMP IN TIMESTAMP
, IN_ALERT_LOGS_LOG_DESC IN VARCHAR2
, IN_KPI_LOG_ID IN NUMBER
) RETURN VARCHAR2 AS
BODY VARCHAR2(4000) := '';
V_KPI_DEF_ID NUMBER := '';
V_BRAND_NAME VARCHAR2(100) := '';
V_KPI_TYPE_ID NUMBER := '';
CURSOR brand_names_cur
IS
Select BR.NAME AS BRAND_NAME INTO V_BRAND_NAME FROM RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION KD JOIN RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION_BRAND KDB ON KD.KPI_DEF_ID = KDB.KPI_DEF_ID JOIN
RATOR_MONITORING_CONFIGURATION.BRAND BR ON KDB.BRAND_ID = BR.BRAND_ID WHERE KD.KPI_DEF_ID = V_KPI_DEF_ID;
BEGIN
Select KPI_DEF_ID INTO V_KPI_DEF_ID FROM KPI_LOGS WHERE KPI_LOG_ID = IN_KPI_LOG_ID;
Select KT.KPI_TYPE_ID INTO V_KPI_TYPE_ID FROM RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION KD JOIN RATOR_MONITORING_CONFIGURATION.KPI_TYPE KT ON KD.KPI_TYPE = KT.KPI_TYPE_ID WHERE KD.KPI_DEF_ID = V_KPI_DEF_ID;
FOR brand_name IN brand_names_cur
LOOP
BODY := BODY || 'BRAND_NAME:' || brand_name.BRAND_NAME || Chr(10) || Chr(13);
END LOOP;
BODY := BODY || 'ALERT_DESCRIPTION:' || to_char(IN_ALERT_LOGS_LOG_DESC);
RETURN BODY;
END BUILD_ALERT_EMAIL_BODY;
Add V_FIRST_RECORD variable
V_FIRST_RECORD Boolean := true;
and use it in your loop like this
if v_first_record then
body := 'BRAND_NAME: '||brane_name.BRAND_NAME;
else
body := body ||','||brane_name.BRAND_NAME;
v_first_record := false;
end if;

Updating a record in database

Using TADOCommand to update a record.
using TADOCommand to insert a new record.
Name of table is Board
Using MS Access database
I get an error
Syntax error in UPDATE/INSERT INTO statement
I can connect and retrieve data just fine. Just never added or updated data before.
My database columns looks like this
ID (auto number)
SN (text)
CardType (text)
Desc (memo)
dbDate (date)
Tech (text)
Code looks like this:
procedure TForm2.BSaveClick(Sender: TObject);
const
sqlStringNew = 'INSERT INTO Board (SN,CardType,Desc,dbDate,Tech) VALUES (:aSN,:aCardType,:aDesc,:aDate,:aTech);';
sqlStringUpdate = 'UPDATE Board SET SN=:aSN, CardType=:aCardType, Desc=:aDesc, dbDate=:aDate, Tech=:aTech WHERE ID = :aID;';
var
ADOCommand : TAdoCommand;
begin
ADOCommand := TADOCommand.Create(nil);
// updating a board
if NewBoard = false then
begin
try
ADOCommand.Connection := adoConnection1;
ADOCommand.Parameters.Clear;
ADOCommand.Commandtext := sqlStringUpdate;
ADOCommand.ParamCheck := false;
ADOCommand.Parameters.ParamByName('aSN').Value := ESerialNumber.Text;
ADOCommand.Parameters.ParamByName('aCardType').Value := ECardType.Text;
ADOCommand.Parameters.ParamByName('aDesc').Value := MDescription.Text;
ADOCommand.Parameters.ParamByName('aDate').Value := strtodate(EDate.Text);
ADOCommand.Parameters.ParamByName('aTech').Value := ETech.Text;
ADOCommand.Parameters.ParamByName('aID').Value := UpdateID;
ADOCommand.Execute;
finally
ADOCommand.Free;
end;
Showmessage('Update Complete');
end;
//if a new board
if NewBoard = True then
Begin
try
ADOCommand.Connection := adoConnection1;
ADOCommand.Parameters.Clear;
ADOCommand.Commandtext := sqlStringNew;
ADOCommand.ParamCheck := false;
ADOCommand.Parameters.ParamByName('aSN').Value := ESerialNumber.Text;
ADOCommand.Parameters.ParamByName('aCardType').Value := ECardType.Text;
ADOCommand.Parameters.ParamByName('aDesc').Value := MDescription.Text;
ADOCommand.Parameters.ParamByName('aDate').Value := strtodate(EDate.Text);
ADOCommand.Parameters.ParamByName('aTech').Value := ETech.Text;
ADOCommand.Execute;
finally
ADOCommand.Free;
end;
NewBoard := false;
BSave.Enabled := false;
NoEdit;
Showmessage('New Record Added');
End;
end;
It is advisable not to use SQL keywords for table and field names. DATE is a function in many SQL dialects. If you choose to use a reserved word/function name for a table/field name, you have to escape it in SQL statement: [Date] for SQL Server and MS Access, "Date" - for Oracle.

SQL : Update Statement : Syntax Error

The Votes column defualt value is 0. Every time when I click the button it must add whichever value I want to the specific row I want.
My error is :
Syntax error : Update statement. [[Delphi]]
This is my code :
procedure TForm4.BitBtn1Click(Sender: TObject);
var
spinval : integer;
begin
spinval := SpinEdit1.value;``
// Candidatetable.Insert;
// Candidatetable['Votes'] := Candidatetable['Votes'] + spinval;
ADOQuery1.Active := false;
ADOQuery1.SQL.Text := 'Update Candidate_table set votes = ''' +
Candidatetable['Votes'] + IntToStr(spinval) +
''' where Name = ''' + DBLookupComboBox1.Text + '''';
ADOQuery1.ExecSQL;
ADOQuery1.Active := false;
ADOQuery1.SQL.Text := 'Select * from Candidate_table';
ADOQuery1.Active := true;
MessageDlgPos('Thank you for voting. You will be logged out.' , mtInformation, [mbOK], 0, 1000, 500);
Form4.Hide;
Form2.Show;
end;
PlEASE HELP =)
Thanks.
I think this is what you are looking for.
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Update Candidate_table');
ADOQuery1.SQL.Add('set votes = votes + :Votes');
ADOQuery1.SQL.Add('where Name = :Name');
ADOQuery1.Parameters[0].Value := spinval;
ADOQuery1.Parameters[1].Value := DBLookupComboBox1.Text;

Why do I get "type mismatch" when I put a date value in SQL?

I am working on a search query function in Delphi 7 (working with a Paradox database) and I keep getting a type mismatch error when selecting between two dates. If I use the date type I get
Project Project1.Exe raised exception class EDBEngineError with message 'Type mismatch in expression.'. Process stoped.'
If i use a dateTime type I get
Project Project1.Exe raised exception class EDBEngineError with message 'Invalid use of keyword. Token : 13? AND Line Number: 8'. Process stoped.'
where 13 is the first digit of the time.
Here's my code:
procedure TForm1.Button1Click(Sender: TObject);
var
Search1 :string;
Search2 :string;
outputveld : string;
datum : TDateTime;
datumZoek: TdateTime;
countmails : integer;
outfile: textfile;
Zoek6MaandenTerug: Double;
begin
Zoek6MaandenTerug := 182.621099;
datum := tdate(now);
datumZoek := datum - Zoek6MaandenTerug;
ShowMessage(DateTimeToStr(Datum));
ShowMessage(DateTimeToStr(datumZoek));
Memo1.Lines.Add(DateTimeToStr(Datum));
//datum := datum- StrToDate('21-4-2004');
{radio button date controll}
{//radio button date controll}
Search1 := Edit1.Text;
Search2 := Edit2.Text;
assignfile(outfile,'text\Emails.txt');
rewrite(outfile);
outputveld := '';
countmails := 0;
{sets up and executesSQL query(Query1)}
Query1.close;
Query1.SQL.Clear;
memo1.Clear;
if Search1 <> EmptyStr then
begin
//Query1.SQL.add('SELECT * FROM Verkoop');
Query1.SQL.add('SELECT DISTINCT Verkoophandelingen.Klantnr, Verkoophandelingen.Type, verkoop.Klantnr, Verkoop.Artikelnr, Artikels.Nummer, Artikels.artikelgroep, Verkoophandelingen.Datum, Klanten.Email');
Query1.SQL.add('FROM Verkoop');
Query1.SQL.add('full Join Artikels ON Verkoop.Artikelnr = Artikels.Nummer');
Query1.SQL.add('full Join Klanten ON Verkoop.Klantnr = Klanten.Nummer');
Query1.SQL.add('full Join Verkoophandelingen ON Verkoop.verkoophandelingnr = Verkoophandelingen.nummer');
Query1.SQL.add('WHERE Verkoophandelingen.Type = "Bestelling" ');
Query1.SQL.add('AND Verkoop.Artikelnr = '+Search1+'');
//Query1.SQL.add('AND Verkoophandelingen.Datum = '+ DateToStr(Date1) +'');
Query1.SQL.add('AND Verkoophandelingen.Datum BETWEEN '+DateTimeToStr(datum)+'');
Query1.SQL.Add('AND '+DateToStr(datumzoek)+'');
Query1.SQL.add('ORDER BY Datum');
Query1.RequestLive := true;
Query1.open;
end
else if Search2 <> EmptyStr then
begin
Query1.SQL.add('SELECT DISTINCT Verkoophandelingen.Klantnr, Verkoophandelingen.Type, verkoop.Klantnr, Verkoop.Artikelnr, Artikels.Nummer, Artikels.artikelgroep, Verkoophandelingen.Datum, Klanten.Email');
Query1.SQL.add('FROM Verkoop');
Query1.SQL.add('full Join Artikels ON Verkoop.Artikelnr = Artikels.Nummer');
Query1.SQL.add('full Join Klanten ON Verkoop.Klantnr = Klanten.Nummer');
Query1.SQL.add('full Join Verkoophandelingen ON Verkoop.verkoophandelingnr = Verkoophandelingen.nummer');
Query1.SQL.add('WHERE Verkoophandelingen.Type = "Bestelling" ');
Query1.SQL.add('AND Artikels.ArtikelGroep = '+Search2+'');
Query1.SQL.add('AND Verkoophandelingen.Datum BETWEEN '+DateToStr(datum)+'');
Query1.SQL.Add('AND '+DateToStr(datumZoek)+'');
Query1.SQL.add('ORDER BY Datum');
Query1.RequestLive := true;
Query1.open;
end;
while not Query1.Eof do
begin
if Query1.FieldByName('Email').AsString <> EmptyStr then
begin
memo1.Lines.Add(Query1.FieldByName('Email').AsString + ';');
writeln(outfile, Query1.FieldByName('Email').AsString+ ';');
Query1.next;
inc(countmails);
end
else
begin
Query1.next;
end;
end;
if Query1.Eof then
begin
CloseFile(outfile);
memo1.lines.add('totaal aantal valid email adressen = ' + IntToStr(countmails));
end;
end;
I hope im posting in the right place.
This is my code after adding parameters for my query still getting
'Type mismatch in expression.'.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, DB, DBTables, DBCtrls;
type
TForm1 = class(TForm)
DataSource1: TDataSource;
Query1: TQuery;
DBGrid1: TDBGrid;
Button1: TButton;
ComboBox1: TComboBox;
Memo1: TMemo;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Button2: TButton;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure ComboBox1Change(Sender:TObject);
procedure Edit1Change(Sender: TObject);
procedure Edit2Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses ComObj;
{$R *.dfm}
procedure TForm1.FormActivate(Sender: TObject);
var
i : integer;
mystringlist : tstringlist;
datum: TDateTime;
Zoek6MaandenTerug : Double;
begin
Zoek6MaandenTerug := 182.621099;
datum := tdate(now);
datum := datum - Zoek6MaandenTerug;
ShowMessage(DateToStr(datum));
Memo1.Lines.Add(DateTimeToStr(Datum));
Memo1.Lines.Add(DateToStr(datum));
//datum := datum- StrToDate('21-4-2004');
MyStringList := TStringList.Create;
{
memo1.Clear;
Edit1.Clear;
Edit2.Clear;
}
try
Session.GetAliasNames(MyStringList);
{ fill a list box with alias names for the user to select from }
for I := 0 to MyStringList.Count - 1 do begin
combobox1.Items.Add(MyStringList[I]);
end
finally
MyStringList.Free;
end;
end;
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
try
Query1.SQL.Clear;
Query1.Databasename := string(combobox1.items[combobox1.ItemIndex]);
except
with Application do
begin
NormalizeTopMosts;
MessageBox(' wrong database ', 'fout..', MB_OK);
RestoreTopMosts;
combobox1.SetFocus;
Exit;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Search1 :String;
Search2 :String;
outputveld : string;
datum : TDateTime;
datumZoek: TDateTime;
countmails : integer;
outfile: textfile;
Zoek6MaandenTerug: Double;
begin
Zoek6MaandenTerug := 182.621099;
datum := tdate(now);
datumZoek := datum - Zoek6MaandenTerug;
ShowMessage(DateTimeToStr(Datum));
ShowMessage(DateTimeToStr(datumZoek));
Memo1.Lines.Add(DateToStr(datum));
Memo1.Lines.Add(DateToStr(datumZoek));
//datum := datum- StrToDate('21-4-2004');
{//radio button date controll}
Search1 := Edit1.Text;
Search2 := Edit2.Text;
assignfile(outfile,'text\Emails.txt');
rewrite(outfile);
outputveld := '';
countmails := 0;
{sets up and executesSQL query(Query1)}
Query1.close;
Query1.SQL.Clear;
memo1.Clear;
if Search1 <> EmptyStr then
begin
//Query1.SQL.add('SELECT * FROM Verkoop');
Query1.SQL.add('SELECT DISTINCT Verkoophandelingen.Klantnr, Verkoophandelingen.Type, verkoop.Klantnr, Verkoop.Artikelnr, Artikels.Nummer, Artikels.artikelgroep, Verkoophandelingen.Datum, Klanten.Email');
Query1.SQL.add('FROM Verkoop');
Query1.SQL.add('full Join Artikels ON Verkoop.Artikelnr = Artikels.Nummer');
Query1.SQL.add('full Join Klanten ON Verkoop.Klantnr = Klanten.Nummer');
Query1.SQL.add('full Join Verkoophandelingen ON Verkoop.verkoophandelingnr = Verkoophandelingen.nummer');
Query1.SQL.add('WHERE Verkoophandelingen.Type = "Bestelling" ');
Query1.SQL.add('AND Verkoop.Artikelnr = :Search1');
//Query1.SQL.add('AND Verkoophandelingen.Datum = '+ DateToStr(Date1) +'');
Query1.SQL.add('AND Verkoophandelingen.Datum BETWEEN :datum AND :datumzoek');
Query1.SQL.add('ORDER BY Datum');
Query1.ParamByName('datumzoek').Value := datumzoek;
Query1.ParamByName('datum').Value := datum;
Query1.ParamByName('Search1').Value := Search1;
Query1.RequestLive := true;
Query1.open;
end
else if Search2 <> EmptyStr then
begin
Query1.SQL.add('SELECT DISTINCT Verkoophandelingen.Klantnr, Verkoophandelingen.Type, verkoop.Klantnr, Verkoop.Artikelnr, Artikels.Nummer, Artikels.artikelgroep, Verkoophandelingen.Datum, Klanten.Email');
Query1.SQL.add('FROM Verkoop');
Query1.SQL.add('full Join Artikels ON Verkoop.Artikelnr = Artikels.Nummer');
Query1.SQL.add('full Join Klanten ON Verkoop.Klantnr = Klanten.Nummer');
Query1.SQL.add('full Join Verkoophandelingen ON Verkoop.verkoophandelingnr = Verkoophandelingen.nummer');
Query1.SQL.add('WHERE Verkoophandelingen.Type = "Bestelling" ');
Query1.SQL.add('AND Artikels.ArtikelGroep = :Search2');
//Query1.SQL.add('AND Verkoophandelingen.Datum BETWEEN '+DateToStr(datum)+'');
//Query1.SQL.Add('AND '+DateToStr(datumZoek)+'');
Query1.SQL.add('AND Verkoophandelingen.Datum BETWEEN :datum AND :datumzoek');
Query1.SQL.add('ORDER BY Datum');
Query1.ParamByName('datumzoek').Value := datumzoek;
Query1.ParamByName('datum').Value := datum;
Query1.ParamByName('Search2').Value := Search2;
Query1.RequestLive := true;
Query1.open;
end;
while not Query1.Eof do
begin
if Query1.FieldByName('Email').AsString <> EmptyStr then
begin
memo1.Lines.Add(Query1.FieldByName('Email').AsString + ';');
writeln(outfile, Query1.FieldByName('Email').AsString+ ';');
Query1.next;
inc(countmails);
end
else
begin
Query1.next;
end;
end;
if Query1.Eof then
begin
CloseFile(outfile);
memo1.lines.add('totaal aantal valid email adressen = ' + IntToStr(countmails));
end;
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
Edit2.Text := '';
end;
procedure TForm1.Edit2Change(Sender: TObject);
begin
Edit1.Text := '';
end;
end.
after adding this
...
Query1.ParamByName('datumzoek').DataType := ftDate;
Query1.ParamByName('datum').DataType := ftDate;
Query1.ParamByName('Search1').DataType := ftInteger;
Query1.ParamByName('datumzoek').Value := datumzoek;
Query1.ParamByName('datum').Value := datum;
Query1.ParamByName('Search1').Value := Search1;
...
the query gets run but with no results, after showing the query,text it seems the parameters have a "?" value ?
...
SELECT DISTINCT Verkoophandelingen.Klantnr, Verkoophandelingen.Type, verkoop.Klantnr, Verkoop.Artikelnr, Artikels.Nummer, Artikels.artikelgroep, Verkoophandelingen.Datum, Klanten.Email
FROM Verkoop
full Join Artikels ON Verkoop.Artikelnr = Artikels.Nummer
full Join Klanten ON Verkoop.Klantnr = Klanten.Nummer
full Join Verkoophandelingen ON Verkoop.verkoophandelingnr = Verkoophandelingen.nummer
WHERE Verkoophandelingen.Type = "Bestelling"
AND Verkoop.Artikelnr = ?
AND Verkoophandelingen.Datum BETWEEN ? AND ?
ORDER BY Datum
...
Perhaps these lines cause the issue:
Query1.SQL.add('AND Verkoophandelingen.Datum BETWEEN '+DateTimeToStr(datum)+'');
Query1.SQL.Add('AND '+DateToStr(datumzoek)+'');
Here you are inserting dates as returned by DateTimeToStr and DateToStr, but you are not delimiting the inserted values in any way, and so the resulting query will look something like this:
...
AND Verkoophandelingen.Datum BETWEEN 21-04-2004
AND 22-04-2004
...
I'm not sure what delimiter Paradox uses for date constants, but I'm almost sure it does use some. Perhaps, it should be ':
...
AND Verkoophandelingen.Datum BETWEEN '21-04-2004'
AND '22-04-2004'
...
Check with the manual for the correct one and fix your code accordingly.
On the other hand, it would be a much better idea to use parametrised queries, as #Rob Kennedy has correctly suggested. In a parametrised query, you use placeholders like :name where argument values should go. So, in your case it might look like this:
...
Query1.SQL.add('WHERE Verkoophandelingen.Type = "Bestelling" ');
Query1.SQL.add('AND Verkoop.Artikelnr = :Search');
Query1.SQL.add('AND Verkoophandelingen.Datum BETWEEN :date1');
Query1.SQL.Add('AND :date2');
...
Before running the query, you'll need to set up the parameters using the TQuery.Params property, something like this:
Query1.Params.CreateParam(ftInteger, 'Search', ptInput).AsInteger := StrToInt(Search1);
Query1.Params.CreateParam(ftDateTime, 'date1', ptInput).AsDateTime := datum;
Query1.Params.CreateParam(ftDateTime, 'date2', ptInput).AsDateTime := datumzoek;
Or, if the Query component auto-fills the Params collection when assigning the SQL statement:
Query1.Params.ParamByName('Search').AsInteger := StrToInt(Search1);
Query1.Params.ParamByName('date1').AsDateTime := datum;
Query1.Params.ParamByName('date2').AsDateTime := datumzoek;
That way you won't need to worry about delimiting values: the component will take care of that.