Ech ... uwierz mi, że jeśli planujesz karierę w IT gdzie będą bazy danych to robisz sobie krzywdę ale na potrzeby studiów ... pomogę bo sam korzystałem z 4p na studiach
http://sqlfiddle.com/#!18/c55548/21
Dodam tylko, że w TSQL dałoby się to napisać prościej i bardziej przejrzyście, a gdyby użyć do tego regexpa przy pomocy CLR:
https://docs.microsoft.com/pl-pl/dotnet/framework/data/adonet/sql/introduction-to-sql-server-clr-integration
z C# to już w zasadzie jednym prostym patternem by się to załatwiło
gdyby sqlfiddle zdechło:
SELECT AlphabeticNum,
case when patindex('%[0-9]/[0-9]%',AlphabeticNum) = 0 then null else
substring(AlphabeticNum,
patindex('%[0-9]/[0-9]%',AlphabeticNum) -
(patindex('%[^ 0-9,0-9]%',reverse(substring(AlphabeticNum,1,patindex('%[0-9]/[0-9]%',AlphabeticNum)))) -1) + 1,
abs((patindex('%[^ 0-9,0-9]%',reverse(substring(AlphabeticNum,1,patindex('%[0-9]/[0-9]%',AlphabeticNum)))) -1)))
end leftready,
case when patindex('%[0-9]/[0-9]%',AlphabeticNum) = 0 then null else
substring(AlphabeticNum,patindex('%[0-9]/[0-9]%',AlphabeticNum)+2,
abs(
case when patindex('%[^ 0-9,0-9]%',substring(AlphabeticNum,patindex('%[0-9]/[0-9]%',AlphabeticNum)+2,len(AlphabeticNum))) -1 = -1 then
len(AlphabeticNum)
else
patindex('%[^ 0-9,0-9]%',substring(AlphabeticNum,patindex('%[0-9]/[0-9]%',AlphabeticNum)+2,len(AlphabeticNum))) -1
end
))
end rightready
from alphanumreg