Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Weekday ordering... 2

Status
Not open for further replies.

Zippeh

Programmer
Sep 24, 2002
56
GB
Bit of a long shot this.

I have a column that contains either Monday-Sunday and would want these ordered by the order they are in the week starting with Monday.

Is it possible to do this in SQL server without introducing a number column for each day, e.g. 1 for Monday, 2 for Tuesday and ordering by this?
 
You can do:

Code:
SELECT weekday
FROM table
ORDER BY CASE weekday
    WHEN 'monday' THEN 1
    WHEN 'tuesday' THEN 2
    WHEN 'wednesday' THEN 3
    WHEN 'thursday' THEN 4
    WHEN 'friday' THEN 5
    WHEN 'saturday' THEN 6
    WHEN 'sunday' THEN 7
  END

But if you are going to do this regularly I would probably add a separate column.

--James
 
That works great :D

I know another column would work better, but I really can't be bothered to go into my DTS which has taken me aaages to get right!!

It'll be fine like this ;)

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top