Delphi Query. > than 1st day of month

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
classicmydac
Posts: 38
Joined: Fri 23 Dec 2005 11:51

Delphi Query. > than 1st day of month

Post by classicmydac » Wed 04 Jan 2006 19:07

I have the function as follows:

function FDOM(Date: TDateTime): TDateTime;
var
Year, Month, Day: Word;
begin
DecodeDate(Date, Year, Month, Day);
Result := EncodeDate(Year, Month, 1);
end;

I use

ShowMessage(DateToStr(FDOM(Now)));
firstdayofmonth := DateToStr(FDOM(Now));

then

temp := 'SELECT SUM(Inv_Nett) FROM Invoice WHERE INV_DATE > (firstdayofmonth)';
Datamodule7.MyQuery_Inv_Sum.SQL.Text := temp;
Datamodule7.MyQuery_Inv_Sum.Open;

I fall over on the fistdayofmonth

What is the correct syntax.

I need to get the sum of all the invoices created in the current month.

Any help appreciated.

SteveW

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

Post by Ikar » Thu 05 Jan 2006 10:35

You should use something like this:

Code: Select all

var
 firstdayofmonth: TDateTime;

 firstdayofmonth := FDOM(Now);

 temp := 'SELECT SUM(Inv_Nett) FROM Invoice WHERE INV_DATE > :firstdayofmonth';
 Datamodule7.MyQuery_Inv_Sum.SQL.Text := temp;
 Datamodule7.MyQuery_Inv_Sum.Params[0].AsDateTime := firstdayofmonth;
 Datamodule7.MyQuery_Inv_Sum.Open; 

Post Reply