Page 1 of 1

Parameters in join condition

Posted: Sun 05 Jun 2005 21:30
by Guest
I get an error 'syntax error or access violation' in MSQuery's Prepare method using parameters in a join condition.
E.g. try following similar code on Northwind:
MSQuery1->SQL->Clear();
MSQuery1->SQL->Add("select * from Products p");
MSQuery1->SQL->Add(" join Suppliers s on s.SupplierID = :pSID");
MSQuery1->SQL->Add(" where p.SupplierID = :pSID");
MSQuery1->ParamByName("pSID")->AsInteger = 4;
MSQuery1->Prepare();
MSQuery1->Open();
Replace the problematic line with
MSQuery1->SQL->Add(" join Suppliers s on s.SupplierID = 4");
or with
MSQuery1->SQL->Add(" join Suppliers s on s.SupplierID = "+IntToStr(4));
and it works. What's wrong ?

Posted: Mon 06 Jun 2005 14:10
by Ikar
Preparing puts some restrictions on the executable query, including using parameters.
For details please refer to MSDN.
Suppose you should refuse from using preparing and/or pass this query to StoredProc.