I need to sort this data to display it in a DataGridView
C#.
In SQL Server
I have the following table:
Día Descripción
----------------
1 Domingo
2 Lunes
3 Martes
4 Miércoles
5 Jueves
6 Viernes
7 Sábado
But in the query I can't sort the day with asc
or desc
, because it won't be sorted correctly:
select * from dias_semana order by dia asc
select * from dias_semana order by dia desc
How can I modify the query to display it sorted like this?
Día Descripción
----------------
2 Lunes
3 Martes
4 Miércoles
5 Jueves
6 Viernes
7 Sábado
1 Domingo
Note: The table contains much more data, but the field dia
is the only one for which I can set an order in the statement select
.
You can use a little trick with the modulo operator (
%
) :Demo