以下是我的数据
Transmitter #1
Transmitter #10
Transmitter #11
Transmitter #2
Transmitter #3
Transmitter #4
Transmitter #5
Transmitter #6
Transmitter #7
Transmitter #8
Transmitter #9
Room 1 Transmitter
Allergy Guard – 1
Allergy Guard – 2
Allergy Guard – 3
Deli Counter
如何将这些数据按字母数字排序。
SELECT * FROM #table
ORDER BY
Name,
CASE
WHEN
patindex('%[0-9]%',substring(Name,len(Name),LEN(Name))) =1
THEN
cast(substring(Name,patindex('%[0-9]%', Name),len(Name)) as int)
END
答案 0 :(得分:0)
以下键应按所需顺序对它们进行排序:
所以:
order by left(name, patindex('%[0-9]%', name + '0') - 1),
len(name),
name
Here是db <>小提琴。