日期:2014-05-17 浏览次数:20534 次
declare @tb table (id varchar(20)) insert into @tb select '1' union all select '2.1' union all select '1.1' union all select '2' union all select '10' union all select '2.1.1' union all select '1.1.1' union all select '1.1.2' union all select '10.1' union all select '3' select * from @tb order by case when charindex('.',id)=0 then CAST( id AS int) else cast(isnull(LEFT(id,charindex('.',id)-1),id) as int) end,id id 1 1.1 1.1.1 1.1.2 2 2.1 2.1.1 3 10 10.1
------解决方案--------------------
上面办法不能解决全部情况,第2位大于10就到了
可以参考http://blog.csdn.net/xys_777/archive/2010/06/15/5672481.aspx