Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Order by DAY

Author  Topic 

rehan
Starting Member

1 Post

Posted - 2007-08-13 : 07:10:23
How to sort day of week starting by Monday?

select first_name name, hire_date , TO_CHAR(hire_date, 'day') Day
from employees
------------------------------...
my above query is working well except that I want to sort the rows order by day of week starting from Monday.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2007-08-13 : 07:15:58
select first_name name, hire_date , DATENAME(weekday,hire_date) Day
from employees
ORDER BY DATEPART(weekday,hire_date)

Jim
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-08-13 : 08:02:46
quote:
Originally posted by rehan

How to sort day of week starting by Monday?

select first_name name, hire_date , TO_CHAR(hire_date, 'day') Day
from employees
------------------------------...
my above query is working well except that I want to sort the rows order by day of week starting from Monday.



FYI, this is Microsoft SQL Server Forum

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2007-08-13 : 08:52:56
Just Try this.


SELECT * ,DATENAME(weekday,hire_date) FROM emp ORDER BY DATEPART(weekday,hire_date-1)
Go to Top of Page
   

- Advertisement -