Delphi Query. > than 1st day of month

Delphi Query. > than 1st day of month

Postby 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
classicmydac
 
Posts: 38
Joined: Fri 23 Dec 2005 11:51

Postby 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;
Ikar
 
Posts: 1693
Joined: Thu 28 Oct 2004 13:56


Return to MySQL Data Access Components