I have 2 rows that contain strings like this :
AX/Aland Island No.5/20142.87/20542.87
KR/Republic of Korea/19-02-2022/19-03-2022
I want everything after two first slashes '/' and before the last slash '/'.
I want my result to be:
20142.87
19-02-2022
I know that we can use functions like substring and charindex but I still don't understand how the syntax is. Please help me. Thank you
CodePudding user response:
If string between the first two slashes will not start with an integer whatsoever and the string after the first 2 slashes is always going to start with an integer then below is the solution.
declare @tbl table(string varchar(200))
insert into @tbl
values('AX/Aland Island No.5/20142.87/20542.87')
,('KR/Republic of Korea/19-02-2022/19-03-2022')
select SUBSTRING(string,PATINDEX('%[/][0-9]%',string) 1,
CHARINDEX('/',SUBSTRING(string,PATINDEX('%[/][0-9]%',string) 1,len(string)))-1)
from
@tbl