有一个字段为编号
内容大体如下:
1-1
1-2
......
1-50
....
50-5
50-6....
Select * from 表 order by 编号
排序不是按照我的意图来排的.
1和11都是挨着的了.
如果按照数字大小来排列呢
内容大体如下:
1-1
1-2
......
1-50
....
50-5
50-6....
Select * from 表 order by 编号
排序不是按照我的意图来排的.
1和11都是挨着的了.
如果按照数字大小来排列呢
order by cast(left(编号,charindex('-',编号)-1) as int)
cast(left(编号,charindex('-',编号)-1) as int),
cast(right(编号,len(编号)-charindex('-',编号)) as int)
substring(charindex('-',编号)+1,len(编号));
Select * from 表 order by CASE WHEN 编号 IS NULL THEN 0 ELSE
substring(1,charindex('-',编号)-1) END asc