I have a table that holds days and times, the day column, can have any of the seven days entered into it, and they are set to data type varchar
. As this table h
IMHO you don't have any reason to store Monday, Tuesday, etc
... If you store the date or datetime value, you can always extract the weekday name from that data at query time when you need it - either using DATENAME
in your query or using the functionality in your presentation tier. The performance cost of doing so doesn't justify storing it separately IMHO. And you should still be able to sort correctly using the native date/datetime data.
Hmm.. that's nasty, the days are stored as verbatim 'Monday', 'Tuesday', etc?
Anyway, just do this:
SELECT *
FROM Requirements
ORDER BY
CASE Day
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