Paw Prints

Wednesday, November 12, 2014

Ordering days of the week

This is a small problem that I’m sure has been solved in a number of different ways, but here is my own take on coding the days of the week in order. Having to categorize information by days can be difficult, as of course, it’s not a list that you can use ORDER BY. Here’s my code:

CREATE TABLE #TMP (ID INT, ADAY VARCHAR(20))
INSERT INTO #TMP(ID, ADAY)
              VALUES (1, 'Sunday'),
              (2, 'Monday'),
              (3, 'Tuesday'),
              (4, 'Wednesday'),
              (5, 'Thursday'),
              (6, 'Friday'),
              (7, 'Saturday')
SELECT
       ADAY
FROM #TMP
ORDER BY ID
DROP TABLE #TMP
Woof woof!
Jason

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.