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 |
|
edp33
Starting Member
9 Posts |
Posted - 2007-03-10 : 18:02:15
|
| I have a column containing reference numbers in the form of 11.11.1.11.1.222.1etcI would like to display these in order like above, however when doing an 'order by' on the column it comes out as 11.11.21010.1010.112etcCan anyone recommend a technique for ordering this type of string?Many thanksJames |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-03-10 : 18:23:38
|
[code]declare @table table( col varchar(10))insert into @tableselect '1' union allselect '1.1' union allselect '1.1.1' union allselect '1.1.2' union allselect '10' union allselect '10.11' union allselect '10.10' union allselect '2' union allselect '2.1'select *from @tableorder by convert(int, dbo.fnParseString(-1, '.', col)), convert(int, dbo.fnParseString(-2, '.', col)), convert(int, dbo.fnParseString(-3, '.', col))/*col ---------- 11.11.1.11.1.222.11010.1010.11*/[/code]Using fnParseString from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033&SearchTerms=fnParseString KH |
 |
|
|
edp33
Starting Member
9 Posts |
Posted - 2007-03-10 : 20:18:09
|
| Many thanks KH that's just what I needed :) |
 |
|
|
|
|
|
|
|