Page 1 of 1

Delphi Query. > than 1st day of month

Posted: Wed 04 Jan 2006 19:07
by classicmydac
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

Posted: Thu 05 Jan 2006 10:35
by Ikar
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;