Используя SUBSTRING()
и PATINDEX()
, возможно упорядочение:
DECLARE @TestTable TABLE (TestVal VARCHAR (20));
INSERT INTO @TestTable (TestVal) VALUES ('Test (1)'), ('Test (10)'), ('Test (2)');
SELECT TestVal
FROM @TestTable
ORDER BY CAST(SUBSTRING(TestVal, PATINDEX('%[0-9]%', TestVal), LEN(TestVal) - PATINDEX('%[0-9]%', TestVal)) AS INT),
LEFT(TestVal, PATINDEX('%[0-9]%', TestVal) - 2)
Выход:
TestVal
---------
Test (1)
Test (2)
Test (10)
Демонстрация на db <> fiddle