Nếu bạn có SQL 2008, bạn có thể sử dụng kiểu dữ liệu phân cấp mới:
WITH Items (ItemNumber) AS (
SELECT '1' UNION ALL SELECT '1.1' UNION ALL SELECT '1.1.1'
UNION ALL SELECT '10' UNION ALL SELECT '11' UNION ALL SELECT '2'
UNION ALL SELECT '2.1' UNION ALL SELECT '20' UNION ALL SELECT '3'
UNION ALL SELECT '30'
)
SELECT *
FROM Items
ORDER BY Convert(hierarchyid, '/' + ItemNumber + '/');