Henry Olive 5 Posted April 27, 2023 Good Day, How can i sort (descending) a table on a calculated field ? Thank You Share this post Link to post
programmerdelphi2k 237 Posted April 27, 2023 (edited) you can try using "FDLocalSQL" as your hub: example: MyDS_FDMemTableX = my real data (or any other dataset) in this dataset create a "new field" as "InternalCalc" ... of course, needs to be a field with size and type as your necessity!!! add the event "OnCalcFields" with your expression for create the logic necessary now, you'll need 1 FDConnection, 1 FDLocalSQL and 1 FDQuery 1 FDConnection using SQLite, with ":memory" database... open it! 1 FDLocalSQL to accomodate your dataset desired... in this case, this dataset will be "MyDS_FDMemTableX" 1 FDQuery will be used to create your SQL select... pointing to your "MyDS_FDMemTableX" now, open your FDConnection, FDLocalSQL, and your FDQuery to see the result for more details see the HELP: Delphi Help -> Example and Samples -> FireDAC.TFDLocalSQL InMemDB Sample procedure TForm1.FDMemTable1CalcFields(DataSet: TDataSet); begin FDMemTable1FullNameInternalCalc.AsString := FDMemTable1LastName.AsString+' '+FDMemTable1FirstName.AsString; end; MyDS_FDMemTableX: FDMemTable1: TFDMemTable; FDMemTable1FirstName: TStringField; FDMemTable1LastName: TStringField; FDMemTable1FullName: TStringField; FDQuery = select * from FDMemTable1 order by FullNameInternalCalc Edited April 27, 2023 by programmerdelphi2k Share this post Link to post