问题描述
我有以下字符串
CTO247 \ SPFI \ Images \ OutImages \ SET04012016 \ BATCH_07042016124801 \ PS_20160407190200550 \ 98394
我需要从上面的字符串中选择PS_20160407190200550.我怎么能做到这一点.我已尝试在已尝试部分中遵循以下解决方案.但是它给出了这样的结果
PS_20160407190200550 \ 98394
我尝试过的事情:
声明@variable varchar(max)
设置@variable =``CTO 247 \ SPFI \ Images \ OutImages \ SET04012016 \ BATCH_07042016124801 \ PS_20160407190200550 \ 98394''
选择Substring(@ variable,CharIndex(``PS_'',@variable),CharIndex(``PS'',@variable))
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))
推荐答案
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))
这篇关于从SQL中给定的字符串中选择一个子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!