尝试如下,它会帮助你..
SELECT ColumnName FROM TableName
ORDER BY CONVERT(INT, Replace(ColumnName, 'Group',''))
SQL小提琴: http ://sqlfiddle.com/#!3/e14a6/7
另一种方式
SELECT ColumnName FROM TableName
ORDER BY LEN(ColumnName),ColumnName
SQL小提琴: http ://sqlfiddle.com/#!3/e14a6/6
另一种方式
SELECT ColumnName FROM TableName order by
case when
PATINDEX('%[^0-9]%',ColumnName) = 0
THEN
data
ELSE
cast(Left(ColumnName,PATINDEX('%[^0-9]%',ColumnName)-1) as int)
END
SQL小提琴: http ://sqlfiddle.com/#!3/14eb5/2
另一种方式
在这里,我使用公用表表达式添加了另一个解决方案试试这个......
with tempCTE(Data, pos)
as
(select data, Patindex('%[0-9]%', data) from sample),
tempCTE2(name, num)
as
(select SUBSTRING(data, 0, pos) name , cast(SUBSTRING(data, pos , LEN(data)) as int) num from tempCTE)
select name + CAST(num as varchar(10)) num1 from tempCTE2 order by name, num asc
SQL小提琴: http ://sqlfiddle.com/#!3/14eb5/3