Problem with Sorting...

Hi,

i have following values in day column.
Day
==
F
M
W
Th
Sa
Su
Tu

Each value in above column denotes F - Friday,  M-Monday, W-Wednesday, Th-Thursday, Sa-Saturday, Su-Sunday, Tu-Tuesday.

I want to sort those values by day... i.e)  M,Tu,W,Th,F.Sa,Su

Anyone please assist with me for this requirement...
gpmsqldevAsked:
Who is Participating?
 
Daniel WilsonCommented:
There are a few ways to handle this ... personally, I would have used an integer in the Day column.

But, given the data you have, I would add a DayLookup table with
Code varchar(2) -- put the codes you show me in here
Name varchar(8) -- put the full name here ... can be useful for displays in other cases
Sequence TinyInt -- put the 0-based sequence numbers here.  In your case, "M" matches up with 0.

Then to sort ...

Select Field1, ... Fieldn, Day
From MyTable Inner Join DayLookup on MyTable.Day = DayLookup.Code
order by DayLookup.Sequence
0
 
Anthony PerkinsCommented:
You could also use a Computed Column to "translate" the code to a more useful tinyint...
0
 
gpmsqldevAuthor Commented:
Its helps me to solve my problem... but i am not using this method . Anyway we have to use M as 1, and Tu as 2, and so on....

So i used CASE statement for this problem.. and finally sorted correctly..
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.