2016-09-26 81 views
1

我有一个字符串com.test.edu.personal.SomeException: this is some error: test message。我需要得到字符串为SomeException: this is some error如何获得SQL Server中某些字符之间的子串

我有我的代码的烦恼:

declare @col varchar(100) 

set @col = 'com.test.edu.personal.SomeException: this is some error: test message' 

SELECT 
    SUBSTRING(@col, 
       LEN(@col) - CHARINDEX(':', @col) - CHARINDEX(':', REVERSE(@col)), 
       LEN(@col) - LEN(LEFT(@col, CHARINDEX ('.', @col))) - LEN(RIGHT(@col, LEN(@col) - CHARINDEX (':', @col)))); 

我越来越nal.SomeException: this is some - 我在这里的东西

+0

什么是定义的规则特定的子字符串? –

回答

0
declare @col varchar(100) 
set @col = 'com.test.edu.personal.SomeException: this is some error: test message' 

Select Substring(@col,Len((substring(@col,1,charindex(':',@col)))) - CharIndex(Reverse('.'), Reverse((substring(@col,1,charindex(':',@col)))))-len('.')+3 ,len(@col)) 

返回

SomeException: this is some error: test message 
+0

谢谢,我需要SomeException:也。我需要提取:“SomeException:这是一些错误” – Lokesh

+0

@Lokesh看到并更新了答案 –

+0

我想我没有正确地问。字符串SomeException是可变的,我可以得到不同的例外。我需要从第一个回到最后。 – Lokesh

相关问题