I'm trying to set up a filter with the actual year and month. Database is MSSQL.
I added DateUtils
to my uses. How can I set up the filter expression to use the YearOf()
function?
How can I add more than one line filter expression? Is this possible?
This is working:
with FDQuery2 do begin
Filtered := False;
Filter := '"Posting Year" = 2021'; //+ 'Posting month = January'
Filtered := True;
end;
Unfortunately, this returns me an error:
with FDQuery2 do begin
Filtered := False;
Filter := '"Posting Year" = YearOf';
Filtered := True;
end;
How can I add a second filter expression?
UPDATE: I used now a little workaround to avoid much more work due to converting TDateTime
, etc.
var
YearFilter: string;
YearFilter := IntToStr(CurrentYear);
YearOf
requires a TDateTime as input argument but you aren't supplying one. Best to fix that before movig on to multiple expression filtering. – MartynA Jan 26 at 9:48YearOf
in your q. YearOf returns a Word, whereasPosting Year
contains a TDateTime so you are not comparing like with like. A rethink is needed, seems to me. Btw there are loads of examples of FDac filter expressions around, try googling a few. – MartynA Jan 26 at 10:15