Parameters in join condition

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Guest

Parameters in join condition

Post by Guest » Sun 05 Jun 2005 21:30

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 ?

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Mon 06 Jun 2005 14:10

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.

Post Reply