2016-09-26 35 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

相關問題