Reverse searching text string in SQL
Posted on 2016-08-31
I'm after some code to use in SQL Server which allows to pick up 2 different user id's stored within a text string.
I have code which will let me pick up the first ID moving left to right but i'd like to pick up the 2nd id moving from right to left.
The text string will be something like 'Name D239383 Name D938373'
I'm using the below code to get the first UID D239383:
Case When string Like '%D[0-9]%' then 'D'+SUBSTRING(string,PATINDEX('%D[0-9]%',string)+1,6) ELSE Null END
replacing 'string' with the proper field name.
I tried using the REVERSE command but couldn't seem to get it to work.
And assistance would be greatly appreciated!