0
我試圖通過使用排序,但排序不能正常工作,因爲我想Sql Server的排序爲nvarchar場
這裏是我的代碼弄清楚這個數據:
SELECT (SELECT LEFT(SUBSTRING(description, PATINDEX('%[0-9.-]%', description), 8000),
PATINDEX('%[^0-9.-]%', SUBSTRING(description, PATINDEX('%[0-9.-]%', description), 8000) + 'X') -1)) as x
FROM dbo.fn_BMS_PPA()
WHERE ppayear = 2017 and actualrootppaid = 112905
and actualmotherppaid != 0 and withchildppa = 0
ORDER BY x
輸出是:
1.1.1
1.1.10
1.1.11
1.1.2
1.1.3
.....
我要的是:
1.1.1
1.1.2
1.1.3
1.1.10
1.1.11
.....
請留意,有時它會1.1
或1.1.1.1
您不能使用「數字排序順序」對字符串進行排序。請參閱:https://dba.stackexchange.com/questions/3828/is-there-a-collation-to-sort-the-following-strings-in-the-follow-order-1-2-3 – Alex