Yuck. This is not something you're going to want to do in T-SQL against large data sets.
DECLARE @x TABLE(HOUSE_NO NVARCHAR(32));
INSERT @x SELECT '2/1 NAWOG'
UNION ALL SELECT '1/1'
UNION ALL SELECT '2/1 A'
UNION ALL SELECT '1/2 A GOLCHA'
UNION ALL SELECT '1'
UNION ALL SELECT '2'
UNION ALL SELECT 'SHASWAT KUTIR'
UNION ALL SELECT '3 A'
UNION ALL SELECT '11/1'
UNION ALL SELECT '11';
DECLARE @n NVARCHAR(10) = N'%[^0-9]%'
SELECT HOUSE_NO FROM @x
ORDER BY CASE
WHEN HOUSE_NO LIKE N'[0-9]' + @n
THEN CONVERT(INT, SUBSTRING(HOUSE_NO, 1, PATINDEX(@n, HOUSE_NO)-1))
WHEN HOUSE_NO NOT LIKE @n THEN CONVERT(INT, HOUSE_NO)
ELSE 2147483647 END,
CASE WHEN HOUSE_NO NOT LIKE @n THEN NULL
ELSE SUBSTRING(HOUSE_NO, PATINDEX(@n, HOUSE_NO), LEN(HOUSE_NO)) END;
What is the point of sorting house numbers in the way anyway?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…