I have a string:
ALIS Predictions Y12 2016-17 Test Based Predictions
I'd like to return the number after the Y and have the following SQL (as an example):
SELECT SUBSTRING('ALIS Predictions Y12 2016-17 Test Based Predictions',
PATINDEX('%[0-9]%',
'ALIS Predictions Y12 2016-17 Test Based Predictions'),
CHARINDEX(' ',
'ALIS Predictions Y12 2016-17 Test Based Predictions'
)
)
But the result I get is:
12 20
Surely the final CHARINDEX should be giving me the expression until the first space? How can I tweak it so that I'm only getting the numbers after the Y?