我需要對字母數字和數字排序應用排序。SQL Server中的字母數字和數字排序
實施例:
319,
519,
620,
1154,
1195,
319lov,
319,
620lov
我需要導致像:
319,
319,
319lov,
519,
620,
620lov,
1154,
1195,
我已應用下面的代碼來進行排序:
SELECT Name
FROM TableName
ORDER BY CAST(CASE
WHEN Name LIKE '[0-9][0-9][0-9][0-9]%' THEN LEFT(Name ,4)
WHEN Name LIKE '[0-9][0-9][0-9]%' THEN LEFT(Name ,3)
ELSE NULL
END AS INT)
GOT導致像:
319,
319lov,
319,
519,
620,
620lov,
1154,
1195,
[http://stackoverflow.com/questions/16862147/sorting-varchar-column-with-alphanumeric-entries](http://stackoverflow.com/questions/16862147/sorting-varchar-列與字母數字條目) – CoSpringsGuy
'AS INT'後'只需添加',Name' – JamieD77
@ JamieD77它工作良好。謝謝 –