I have a string in multiple URLs starting with two characters followed by between 1-6 numbers e.g. 'SO123456' This string is rarely in the same position within the URL. Following the string is either .html or whitespace.
SELECT SUBSTRING(URL,PATINDEX('%SO[0-9]%',URL),8)
FROM Table
WHERE URL LIKE '%SO[0-9]%'
This code returns 'SO12.htm' if the string is shorter than 8 characters.
Not all of the URLs have this string, and if that's the case then I still need the query to produce 'Null'.
I'm trying to return the exact length of the string. Can anyone help me with a way to solve this please? Can you find the length of a wildcard string to use within the substring so that only the exact string length is returned?
Many Thanks.