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.
| Author |
Topic |
|
dim
Yak Posting Veteran
57 Posts |
Posted - 2010-11-26 : 14:11:02
|
| Hi,I have a database column Month defined as varvhar coming out as random months. What I need to do is for each year the month column lays out data in the sacending order of the months. The systax are as follows:SELECT RTRIM(dbo.vw2_Dim_Date.Month_Name) + ' ' + cast(ltrim (dbo.vw2_Dim_Date.Calendar_Year) as varchar) as Month_Name,dbo.vw2_Dim_Date.Month_Name as Month_Name_Date_Dim,dbo.vw2_Dim_Date.Calendar_Year as Calender_Year,AVG(cast(b.Shift as float)/60) AS Shift_Average,FROM a, b, c, dbo.vw2_Dim_DateWHERE b.F_Key = a.F_Keyand b.Key = a.Keyand b.y = a.yand c.y = a.y--and dbo.vw2_Dim_Date.Date between '04/30/2010' and '06/01/2010'and a.date_key = dbo.vw2_Dim_Date.date_keygroup byRTRIM(dbo.vw2_Dim_Date.Month_Name) + ' ' + cast(ltrim (dbo.vw2_Dim_Date.Calendar_Year) as varchar),dbo.vw2_Dim_Date.Month_Name,dbo.vw2_Dim_Date.Calendar_Year Please let me know of any ways to have the month name column as ascending order sort like Janurary, February, March.....etc..Thank You,dimDp |
|
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2010-11-26 : 14:14:37
|
Add ORDER BY MONTH(dbo.vw2_Dim_Date.Date) ASC at the bottom of the query Poor planning on your part does not constitute an emergency on my part. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-11-27 : 01:38:04
|
| if you've multiple year also coming make sure you add YEAR(Date) also in ORDER BY------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|
|