SOLVED: How to sort DESC in DBGrid? lazarus / 16-Databases ---------------------------------------------------------------------- SaraT · 2020-01-30 04:38 Hi guys To sort ASC in DBGrid, I use the code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SQLQuery1.IndexFieldNames := Column.FieldName; Results of the above code: 1 2 3 ... How can I sort DESC the column in DBGrid? i.e: ... 3 2 1 ---------------------------------------------------------------------- mangakissa · 2020-01-30 07:43 SQLQuery1.IndexFieldNames := Column.FieldName DESC ---------------------------------------------------------------------- SaraT · 2020-01-30 08:36 Quote from: mangakissa on January 30, 2020, 08:43:55 amSQLQuery1.IndexFieldNames := Column.FieldName DESC Thanks but you know very well that code doesn't work. ---------------------------------------------------------------------- madref · 2020-01-30 10:14 Make your query DESC with 'ORDER BY Your_Field DESC'. then sql looks like this Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   cSQL := 'SELECT Seizoen AS Sei_ID, tbl_Seizoenen.Sei_Periode, Sei_Letter FROM qry_Overzicht_Evaluaties ' +          'INNER JOIN tbl_Seizoenen ON tbl_Seizoenen.SEI_ID = qry_Overzicht_Evaluaties.Seizoen ' +          'GROUP BY Seizoen ' +          'UNION SELECT 0, "(All)" As Sei_Periode, "ZZ" ' +          'FROM tbl_Seizoenen ' +          'ORDER BY Sei_Letter DESC;'; ---------------------------------------------------------------------- johnmc · 2020-01-30 10:42 I use this form of query: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SQLQuery.Close;        SQLQuery.SQL.Text :=          ' SELECT * from wine_TBL ORDER BY WineName COLLATE NOCASE DESC ';        SQLQuery.Open; ---------------------------------------------------------------------- mangakissa · 2020-01-31 08:17 Quote from: SaraT on January 30, 2020, 09:36:49 amQuote from: mangakissa on January 30, 2020, 08:43:55 amSQLQuery1.IndexFieldNames := Column.FieldName DESC Thanks but you know very well that code doesn't work.  In Delphi does. It should be compatible with lazarus ---------------------------------------------------------------------- rvk · 2020-01-31 11:36 Quote from: mangakissa on January 31, 2020, 09:17:57 amQuote from: SaraT on January 30, 2020, 09:36:49 amQuote from: mangakissa on January 30, 2020, 08:43:55 amSQLQuery1.IndexFieldNames := Column.FieldName DESC Thanks but you know very well that code doesn't work.  In Delphi does. It should be compatible with lazarus  Without ; after the line? DESC isn't really a reserved word so that doesn't work either. Did you mean: ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SQLQuery1.IndexFieldNames := Column.FieldName + ' DESC'; Of maybe you meant: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i FDQuery1.IndexFieldNames := 'order_date;customer_name:D';(like mentioned here http://docwiki.embarcadero.com/Libraries/Rio/en/FireDAC .Comp.Client.TFDMemTable.IndexFieldNames) But that's not Lazarus compatible.