A pretty flexible way to get what you want is by the use of a recursive CTE
. The CTE expression will essentially give you the position and the corresponding index of all '/' contained in the string:
DECLARE @string VARCHAR(MAX) = 'CMS/00014456582/693362/004535/JCR_110914_NEW_4535 CMS'
;WITH CTE AS (
SELECT CHARINDEX('/', @string) AS pos, idx = 1
UNION ALL
SELECT CHARINDEX('/', @string, pos+1) AS pos, idx + 1
FROM CTE
WHERE pos > 0
)
SELECT *
FROM CTE
produces:
pos idx
-------
4 1
16 2
23 3
30 4
0 5
Using the above CTE you can easily extract any part of the string contained within, say, 1st and 2nd slashes, or 2nd and 3rd, etc:
;WITH CTE AS (
SELECT CHARINDEX('/', @string) AS pos, idx = 1
UNION ALL
SELECT CHARINDEX('/', @string, pos+1) AS pos, idx + 1
FROM CTE
WHERE pos > 0
)
SELECT SUBSTRING(@string,
(SELECT pos FROM CTE WHERE idx = 2) + 1,
(SELECT pos FROM CTE WHERE idx = 3) - (SELECT pos FROM CTE WHERE idx = 2) - 1)