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
 Sort Order by Month

Author  Topic 

phanicrn
Starting Member

42 Posts

Posted - 2007-11-06 : 16:20:37
SELECT TOP (100) PERCENT Calendar_Key, Calendar_Date, Calendar_Year, Calendar_Month, Calendar_Quarter, Calendar_week, Calendar_DayOfMonth,
Calendar_DayOfYear, Calendar_Datename, Calendar_EndOfMonth, Calendar_EndOfQuarter, Calendar_EndOfYear,
CAST(CASE WHEN Calendar_Month = 1 THEN 'January' WHEN Calendar_Month = 2 THEN 'February' WHEN Calendar_Month = 3 THEN 'March' WHEN Calendar_Month
= 4 THEN 'April' WHEN Calendar_Month = 5 THEN 'May' WHEN Calendar_Month = 6 THEN 'June' WHEN Calendar_Month = 7 THEN 'July' WHEN Calendar_Month
= 8 THEN 'August' WHEN Calendar_Month = 9 THEN 'September' WHEN Calendar_Month = 10 THEN 'October' WHEN Calendar_Month = 11 THEN 'November'
WHEN Calendar_Month = 12 THEN 'December' END AS char(9)) AS Month
FROM EDW.Calendar_Dim
WHERE (Calendar_Year IS NOT NULL)
ORDER BY Calendar_Year, Calendar_Month

I have two vlaue prompts.. which show year & month, when we select year, it shows in order. when we select month, since its character, it showing from 'April, August....

but i want month prompt to start from Jan...

Any suggestion on how to modify..

thanks
Phanicrn

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-06 : 17:03:27
Doesn't your current query gives you what you wanted ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

phanicrn
Starting Member

42 Posts

Posted - 2007-11-06 : 17:10:05
this sql gives, but when users select value,since month is character it shows order from Aug, April
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-06 : 17:16:11
Then it is a presentation problem in your combo box.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-06 : 17:16:34
you are ordering by Calendar_Month, isn't that the integer value of the month ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

phanicrn
Starting Member

42 Posts

Posted - 2007-11-06 : 17:21:29
calendar_month is int16, but when i write case statement on calendar_month, so datatype gets converted to character..
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-06 : 17:24:58
quote:
Originally posted by phanicrn

calendar_month is int16, but when i write case statement on calendar_month, so datatype gets converted to character..


No. It didn't. That is the month column. calendar_month remains unchanged.

Did you try running your query in Query Analyzer or SSMS ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

phanicrn
Starting Member

42 Posts

Posted - 2007-11-06 : 17:30:20
i didnt get you
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-06 : 17:31:44
which part ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-11-07 : 00:45:21
Return calender_month to the front end and then when populating it to drop down, apply the logic there to show month names instead of month values

Madhivanan

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

- Advertisement -