I admit I am not experienced with using SQL directly in Delphi. But I tried now with a small project. It execute a this SQL
SELECT [Type], [Sum] = Count(*)
FROM exceptionrow
WHERE LogDate >= :FromDate
AND LOGDATE <= :ToDate
GROUP BY [type]
ORDER BY [sum] DESC
Where FromDate and ToDate is params as TDateTime. Here is the event to execute.
procedure TLogsStats.CollectTopExceptions(aFromDate, aToDate: TDateTime);
begin
qryTopExceptions.ParamByName('FromDate').AsDate := aFromDate;
qryTopExceptions.ParamByName('ToDate').AsDate := aToDate;
cdsTopExceptions.Close;
cdsTopExceptions.Open;
end;
I do get result in a DBGrid but not the same as when running directly in SQL Studio with static date. There is too few rows. I copied the setup from this project. I think it is strange that 5 components is needed to just run a sql query. See image.
Can it be simplified ? Here are my declarations of the components.
SQLConnection: TSQLConnection;
qryTopExceptions: TSQLDataSet;
dspTopExceptions: TDataSetProvider;
cdsTopExceptions: TClientDataSet;
dsTopExceptions: TDataSource;
EDIT: Finally I found the reason it didn't work. I suspect faulty drivers etc but it was a simple stupid error. I was connected to a small test database instead of the bigger database. Now it works fine with 3 components and the parameters. Sorry for taken your time :)
SQLConnection: TSQLConnection;
qryTopExceptions: TSQLDataSet;
dsTopExceptions: TDataSource;
Regards