A quick way is to use the delimited split function written by Jeff Moden on SQLServerCentral.
If you've got that created, then the query is as simple as:
(5, because you want the fifth string in the set).
This method will work on many versions of SQL Server, but is limited to the size of input string it'll accept.
If you've got SQL Server 2016, you could just use the in-built 'STRING_SPLIT' function, but there are no guarantees that data will be returned in the right order...
answered Apr 19 at 02:16 PM
If it is always going to be 3 digits then something simple like SUBSTRING would work
o/w you probably want to create a function - Or you could bodge it by nesting CHARINDEX. The example below should give you an idea of how to do it:
SELECT CHARINDEX('',@item, CHARINDEX('',@item,CHARINDEX('_',@item)+1) +1 )
answered Apr 18 at 11:51 AM