Hello

How can you sort the table by day of the week (not asc/desc ) in order of Monday-Sunday?

Table - schedule.

Field - [Day of the week].

The values ​​in the fields correspond to Monday - Sunday, taken from PickList DBGridEh1.

  • Combine with auxiliary table that specifies the order for days. - alexlz
  • one
    Create a hidden numeric field with the week code. Sort by it, then the days of the week will be presented in ascending order. - IntegralAL

1 answer 1

 .. ORDER BY DatePart('w', [День недели], 2); 

2 here means the constant vbMonday - start counting from Monday

  • Thanks for the tip. Hmm .. but when writing "adoQuery1.SQL.Add ('SELECT * FROM schedule ORDER BY DatePart (' w ', [Day of the week], 2');" checkout "Too few parameters. Required 1.", can I Wrong wrote? - TerenyaRoman
  • one
    > Thanks for the tip. > Hmm .. but when writing "adoQuery1.SQL.Add ('SELECT * FROM schedule ORDER BY> DatePart (' w ', [Day of the week], 2');" highlighting "There are too few parameters.> Required 1.", maybe I wrote something wrong? I have a quotation mark in the DatePart ('w', [Day of the week], 2 ') after 2, but I don’t have a closing bracket, and most likely the quotes framing w are to be escaped - Donil