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 |
|
hugh_mungo
Starting Member
10 Posts |
Posted - 2006-03-16 : 06:21:04
|
| Hi,I have a character column in a table that contains values such as0-5050-100100-150150-200200-250When I order on this column they results come out as 0-50100-150150-200200-25050-100is there a way I can order them numerically using sql? |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-03-16 : 06:41:12
|
| Why did you store the range in varchar column?It will be easy to maintain if you have two columns range1 and range2 with int datatypesOne of the tricky ways is select * from yourTable order by len(col),colMadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-03-16 : 06:59:27
|
[code]select colfrom( select '0-50' as col union all select '50-100' as col union all select '100-150' as col union all select '150-200' as col union all select '150-220' as col union all select '200-250' as col) corder by convert(int, left(col, charindex('-', col) - 1)), col[/code] KH |
 |
|
|
|
|
|