Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have following string
CTO247\SPFI\Images\OutImages\SET04012016\BATCH_07042016124801\PS_20160407190200550\98394

I need to select PS_20160407190200550 from the above string. How can I achieve this. I have tried following solution in tried section. But it gives result like this

PS_20160407190200550\98394

What I have tried:

declare @variable varchar(max)
set @variable = 'CTO 247\SPFI\Images\OutImages\SET04012016\BATCH_07042016124801\PS_20160407190200550\98394'
select Substring(@variable,CharIndex('PS_', @variable), CharIndex('PS', @variable))
Posted
Updated 19-Apr-16 5:31am

1 solution

It's easiest just to do the splitting over two lines ...

DECLARE @variable VARCHAR(MAX)
SET @variable = 'CTO 247\SPFI\Images\OutImages\SET04012016\BATCH_07042016124801\PS_20160407190200550\98394'
SET @variable = SUBSTRING(@variable,CharIndex('PS_', @variable), LEN(@variable))
SELECT SUBSTRING(@variable, 0, CHARINDEX('\', @variable))
 
Share this answer
 
Comments
touseef4pk 19-Apr-16 11:43am    
Chaa gay hen ap. Means you are great. Thanks for help.
Richard Deeming 19-Apr-16 12:10pm    
Google Translate thinks that should be "Chaa gaye hain aap" - छा गए हैं आप

:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900