Everyone who has said the edge cases are the trick is correct, but if the structure is consistent this should work as well with simple string functions. Example with three tests:
declare @test varchar(max) = 'Type=A-SRID=152-WOID=3'
declare @test2 varchar(max) = 'SRID=152-WOID=3'
declare @test3 varchar(max) = 'Type=A-WOID=3'
select iif(charindex('SRID=', @test) > 0, substring(@test, charindex('SRID=', @test)+5, charindex('-',substring(@test, charindex('SRID=', @test)+5, 8000))-1),'')
select iif(charindex('SRID=', @test2) > 0, substring(@test2, charindex('SRID=', @test2)+5, charindex('-',substring(@test2, charindex('SRID=', @test2)+5, 8000))-1),'')
select iif(charindex('SRID=', @test3) > 0, substring(@test3, charindex('SRID=', @test3)+5, charindex('-',substring(@test3, charindex('SRID=', @test3)+5, 8000))-1),'')
Edit: you are correct you need handling for if the string ends after the value you are looking for, but in that case a simple case statement will handle it. It can still be done with string functions:
select case when charindex('-',substring(@test, charindex('SRID=', @test)+5, 8000))-1 < 0
then substring(@test, charindex('SRID=', @test)+5, 8000)
else iif(charindex('SRID=', @test) > 0, substring(@test, charindex('SRID=', @test)+5, charindex('-',substring(@test, charindex('SRID=', @test)+5, 8000))-1),'')
end
-? WillTypeandWIODalways exist? Cn a value ever contain a-? Please post some more examples of all the different cases.The trick is not finding the data, it's covering all the edge cases