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
 SQL Server 2008 Forums
 Analysis Server and Reporting Services (2008)
 Sorting week number ASC

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2010-06-24 : 11:24:08
Hi i've a dataset called week which is order by week num,ber ASC that i use to populate a drop down list to filter my report by week number.

Each time i run the query the week_no is ordered like
1
10
11
12
.
I'd like to get the sorting as
1
2
3
4
.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-24 : 11:47:47
Is it possible to convert the column to int in the ORDER BY?
Because the actual sort looks like the column datatype is varchar or so.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2010-06-24 : 12:28:01
Aye that was the problem i went back to the table and the col was set to Varchat i converted it to an int and it worked.

thanks
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-24 : 14:18:34
glad to help


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-24 : 14:36:43
Or...

ORDER BY LEN(WeekNum), WeekNum



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-25 : 03:48:27
or

http://beyondrelational.com/blogs/madhivanan/archive/2008/07/21/ordering-interger-values-stored-in-varchar-column.aspx

Madhivanan

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

- Advertisement -