I have this query :
SELECT * FROM Vente WHERE
(DatePart ("d", Vente.DateDebut)=01) and
(DatePart ("m", Vente.DateDebut)=06) and
(DatePart ("yyyy", Vente.DateDebut)=2017);
This query is working fine in MS Access 2010 , but when I try to excute it from TFDQuery
component , it give me an error :
[FireDAC][Phys][ODBC][Microsoft][Pilote ODBC Microsoft Access] Too few parameters. 3 Expected ...
What's the problem? How can I fix that?
Update:
It seems like the problem in the DatePart ()
function , because I try also this:
SELECT DatePart ("d", Vente.DateDebut) FROM Vente
And it give me the same error , just with "3 Expected ..." becomes "1 Expected ...".
My best guess is, that the driver rejects your query because of " (quotation mark) string escapes that you used. For example FireDAC MS Access metadata class internally uses ' (apostrophe) to escape string values. If I'm right, you'll be having trouble to write SQL queries with string constants executable in a FireDAC application as well as in MS Access, because for FireDAC you would write query like this (apostrophe must be escaped in Delphi code):
SELECT DatePart(''d'', Vente.DateDebut) FROM Vente
Which is something that MS Access won't understand. It needs quotation marks, which are in turn not acceptable for FireDAC:
SELECT DatePart("d", Vente.DateDebut) FROM Vente
I'm not aware of a way that would allow you to write commands with string constants for FireDAC as well as MS Access. This should work in FireDAC (won't in MS Access):
SELECT * FROM Vente WHERE
({EXTRACT(DAY, Vente.DateDebut)} = :Day) AND
({EXTRACT(MONTH, Vente.DateDebut)} = :Month) AND
({EXTRACT(YEAR, Vente.DateDebut)} = :Year)
After preprocessing for MS Access it should produce command like this (notice the apostrophe):
SELECT * FROM Vente WHERE
(DATEPART('d', Vente.DateDebut) = :Day) AND
(DATEPART('m', Vente.DateDebut) = :Month) AND
(DATEPART('yyyy', Vente.DateDebut) = :Year)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.