Lazarus

Programming => Databases => Topic started by: SaraT on January 30, 2020, 05:38:01 am

Title: SOLVED: How to sort DESC in DBGrid?
Post by: SaraT on January 30, 2020, 05:38:01 am
Hi guys :)
To sort ASC in DBGrid, I use the code:
Code: Pascal  [Select][+][-]
  1. 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

Title: Re: How to sort DESC in DBGrid?
Post by: mangakissa on January 30, 2020, 08:43:55 am
SQLQuery1.IndexFieldNames := Column.FieldName DESC
Title: Re: How to sort DESC in DBGrid?
Post by: SaraT on January 30, 2020, 09:36:49 am
SQLQuery1.IndexFieldNames := Column.FieldName DESC

Thanks but you know very well that code doesn't work.  :(
Title: Re: How to sort DESC in DBGrid?
Post by: madref on January 30, 2020, 11:14:51 am
Make your query DESC with 'ORDER BY Your_Field DESC'.


then sql looks like this

Code: MySQL  [Select][+][-]
  1.   cSQL := 'SELECT Seizoen AS Sei_ID, tbl_Seizoenen.Sei_Periode, Sei_Letter FROM qry_Overzicht_Evaluaties ' +
  2.           'INNER JOIN tbl_Seizoenen ON tbl_Seizoenen.SEI_ID = qry_Overzicht_Evaluaties.Seizoen ' +
  3.           'GROUP BY Seizoen ' +
  4.           'UNION SELECT 0, "(All)" As Sei_Periode, "ZZ" ' +
  5.           'FROM tbl_Seizoenen ' +
  6.           'ORDER BY Sei_Letter DESC;';
Title: Re: How to sort DESC in DBGrid?
Post by: johnmc on January 30, 2020, 11:42:18 am
I use this form of query:
Code: Pascal  [Select][+][-]
  1. SQLQuery.Close;
  2.         SQLQuery.SQL.Text :=
  3.           ' SELECT * from wine_TBL ORDER BY WineName COLLATE NOCASE DESC ';
  4.         SQLQuery.Open;
Title: Re: How to sort DESC in DBGrid?
Post by: mangakissa on January 31, 2020, 09:17:57 am
SQLQuery1.IndexFieldNames := Column.FieldName DESC

Thanks but you know very well that code doesn't work.  :(
In Delphi does. It should be compatible with lazarus  %)
Title: Re: How to sort DESC in DBGrid?
Post by: rvk on January 31, 2020, 12:36:21 pm
SQLQuery1.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][+][-]
  1. SQLQuery1.IndexFieldNames := Column.FieldName + ' DESC';

Of maybe you meant:
Code: Pascal  [Select][+][-]
  1. 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.
TinyPortal © 2005-2018