First, I assume you have only one number in your pattern. If not, you can extend the below code assuming you have some known rule for detecting the right string.
So, this code here below (which I don't have any machine to test on currently...) finds the number start index and length, extracts it and converts it into an integer (I assume the string is inside a variable named @data
):
DECLARE @numindex int;
SELECT @numindex = PATINDEX('[0-9]', @data);
DECLARE @numlength int;
SELECT @numlength = PATINDEX('[^0-9]', SUBSTRING(@data, @numindex, LEN(DATA) - @numindex - 1));
-- This is the result below
SELECT CONVERT(int, SUBSTRING(@data, @numindex, @numlength))
If all the assumptions I wrote do suit you, you could either create a scalar valued function from this, or add this directly to the query (which may make the query a bit unreadable...).
Regarding performance, this is obviously not ideal to sort like this on every query. If this is going to happen a lot and the data isn't going to change frequently, maybe creating a view that would possibly be cached would improve the performance.