我有以下SQL:如何按數字順序對字母數字SQL Server NVARCHAR列進行排序?
SELECT fldTitle
FROM tblTrafficAlerts
ORDER BY fldTitle
它返回下列順序的結果(從NVARCHAR
列):
A1M northbound within J17 Congestion
M1 J19 southbound exit Congestion
M1 southbound between J2 and J1 Congestion
M23 northbound between J8 and J7 Congestion
M25 anti-clockwise between J13 and J12 Congestion
M25 clockwise between J8 and J9 Broken down vehicle
M3 eastbound at the Fleet services between J5 and J4A Congestion
M4 J19 westbound exit Congestion
你會看到M23和M25是在M3以上所列和M4行,這看起來並不令人滿意,而且如果掃描更長的結果列表,您不希望按照此順序讀取它們。
所以我想按字母順序排序,然後數值結果,看起來像:
A1M northbound within J17 Congestion
M1 J19 southbound exit Congestion
M1 southbound between J2 and J1 Congestion
M3 eastbound at the Fleet services between J5 and J4A Congestion
M4 J19 westbound exit Congestion
M23 northbound between J8 and J7 Congestion
M25 anti-clockwise between J13 and J12 Congestion
M25 clockwise between J8 and J9 Broken down vehicle
因此M3和M4出現上述M23和M25。
標籤DBMS。 (答案可能取決於使用的產品。) – jarlh
Microsoft SQL Server 2008 - 感謝您的標籤編輯建議! – Rich
@JaydipJ該運營商尚未表示未按預期工作。他問的是如何排序與默認 –