I am using SQL Server 2014 and I have a column (called RankDetails) in my table. I need to extract 2 specific numbers which appear in those strings.
Rank Details column:
RankDetails
#1 of 223 hotels in Maldives
#3 of 223 hotels in Maldives
...
#10 of 223 hotels in Maldives
...
#126 of 223 hotels in Maldives
What I am looking for:
RankDetails Rank OutOf
#1 of 223 hotels in Maldives 1 223
#3 of 223 hotels in Maldives 3 223
... ... ...
#10 of 223 hotels in Maldives 10 223
... ... ...
#126 of 223 hotels in Maldives 126 223
I am able to extract the [Rank] column by using the following T-SQL code:
select
Rank = SUBSTRING([RankDetails], PATINDEX('%[0-9]%', [RankDetails]), PATINDEX('%[0-9][a-z !@#$%^&*(()_]%', [RankDetails]) - PATINDEX('%[0-9]%', [RankDetails]) + 1),
*
from [MyTable]
However, I am having a hard time trying to figure out how to output the [OutOf] column.
I had a look here: SQL - How to return a set of numbers after a specific word for a possible solution but still cannot make it work.