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

関連する問題