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 |
|
sqldev6363
Yak Posting Veteran
54 Posts |
Posted - 2009-01-06 : 13:51:12
|
| Hi,I have table tbl1 having column col1 contains valuescol1 10 10020305060When I am displaying in ascending order it is displaying in the above orderBut i need to display in this ordercol1102030405060100How can i display in the above order???Can any one help me?dev |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sqldev6363
Yak Posting Veteran
54 Posts |
Posted - 2009-01-06 : 14:13:23
|
Yes, data type is varchar because, i have one more row which is 'tot'col11010020304050totThese are the values i have??Then how i will get the asc order??quote: Originally posted by tkizer What is the data type of col1? I believe your answer is going to be varchar or similar. In order to get that kind of sort, you can either modify col1 so that it is using the proper data type or you can convert/cast the data in the query.ORDER BY CONVERT(int, col1)Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
dev |
 |
|
|
ygeorge
Yak Posting Veteran
68 Posts |
Posted - 2009-01-06 : 15:04:14
|
| Order By IsNumeric(col1) Desc, Case When IsNumeric(col1) = 1 Then Convert(Int, col1) End,col1 |
 |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-01-06 : 15:10:01
|
| I would consider converting the column to an int datatype and getting rid of the "tot" row. You should do your calculations separately rather than keep the total as one of the rows. |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-06 : 23:23:56
|
| select col1 from urtable order by cast(col1 as int) |
 |
|
|
|
|
|