Skip to content
Advertisement

TSQL: How to use charindex ? – Finding a specific word in a variable string between specific characters

I have this string: 'Level 1 - Level 2 - Level 3 - Level 4 - Level 5 - Level 6 - Level 7'

I would like to get the Level 6 word and level 5 word apart. I did try to google a few things, but they are not really helping me in this case. Because the levels will have different words and such, so it will be different lengths.

I tried the following but I know this will only select the first word between these: ‘-‘ ‘-‘

Can anyone of you help me on the right path ?

I am currently still new to using CHARINDEX.

Advertisement

Answer

You can try this below logic-

DEMO HERE

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement