Order Range / setrange by multiple columns

Is there a possibility to get a range that is sorted by two columns?



Sort by Column1 first and then by Column2


Column1   Column2

1                  Date 1

2                  Date 3

2                  Date 5

3                  Date 2

3                  Date 4

3                  Date 6

4                  Date 7

    procedure SortedData ()
        Tab1: Record "Tab1";
        Tab1.SetRange("Column1", "Column1");
        //......What do i have to do now to sort by column 2 as well?
  • Hi,

    Using SETRANGE doesn't change how your data is sorted! It only limits which rows are displayed. It's "just" a filter.

    If you like to change the way data are sorted, then you have define a new key including the fields it should sort by.

    In your example, then I assume that you only have two columns/fields in the Tab1 table. In that case Column1 would be the primary key (if the same date is only allowed once). So technically it would always sort by first the primary key and then the first (and only) field. If the same date is allowed more than once, then you need more fields in your primary key, otherwise the key would not be unique.

    If column1 and column2 are only two fields in the table, then you would need define a new key with Column1 and Column2.

Reply Children
No Data