Registriert seit: 5. Jun 2020
10 Beiträge
|
How to pass a computed date variable to a where sql command
7. Jun 2020, 05:08
Datenbank: SQL • Version: QDA Version9 • Zugriff über: Delphi
Hi All,
I am Pretty new by Delphi and get stucked in a line of my Code:
when I pass my date (f.instance: 01.07.2020) works fine, if I Change this against the same value computed by a function drives in error.
I suspect is something trivial as a data Format or data onversion, but please I Need your help, give me a hint.
many thanks in Advance and regards
Enclosed my Code and Error Messages:
//////////////////////////////////
Error is coming from (***)
Beim Debugging:
variable dt contains the Right value: 01.07.2020
function GetDate contains (compile error on Expression)-> I calculate here just the first of next month
ERROR Message:
RUNTIME ERROR
Unknown data type for Parameter 'dt' when evaluating instruction REt($0,$0,$0,$0,").
...
///////////////////////////////////
Code:
function GetDate: string ;
var
strTimeReportFormat: String;
dateNow : DateTime;
myDate : TDateTime;
strDate : String;
dateReport : String;
Year, Month, Day : Word;
begin
dateNow := now;
dateNextMonth := IncMonth(dateNow );
DecodeDate(dateNextMonth, Year, Month, Day);
dateReport := EncodeDate(Year, Month, 1);
strDate := 'dd.mm.yyyy';
Result := FormatDateTime(strDate, dateReport);
end;
procedure Main:
var
….
strTimeMonth : String;
v : variant;
dt : TDateTime;
….
begin
….
strTimeMonth:=GetDate;
v := strTimeMonth;
dt := VarToDateTime(v);
qry.DatabaseName := 'QDA8';
qry.Sql.Add('SELECT MyDB.TargetDate,MyDB.column02,MyDB.column04,MyDB.c olumn06,MyDB.column08, MyDB,MyDB.column09 FIRMA,');
qry.Sql.Add('FROM MyDB');
qry.Sql.Add('WHERE TargetDate = :dt'); ---> (***)
qry.Sql.Add('Order by FIRMA');
…..strSQL := qry.Sql.GetText;
qry.Open;
strHeader := 'TargetDate;column02;column04;FIRMA;column09;colum n06;column08';
Writeln(tfFilePointer, strHeader);
tsSQLListe.Add(cTrenner + qry.FieldByName('TargetDate').AsString);
tsSQLListe.Add(cTrenner + qry.FieldByName('column02').AsString);
tsSQLListe.Add(cTrenner + qry.FieldByName('FIRMA').AsString);
tsSQLListe.Add(cTrenner + qry.FieldByName('column04').AsString);
tsSQLListe.Add(cTrenner + qry.FieldByName('column06').AsString);
tsSQLListe.Add(cTrenner + qry.FieldByName('column08').AsString);
tsSQLListe.Add(cTrenner + qry.FieldByName('column09').AsString);
|