如何在SQL Server中的某些字符之间获取子字符串

时间:2022-08-22 13:16:38

I have a string com.test.edu.personal.SomeException: this is some error: test message. I need to get the string as SomeException: this is some error.

我有一个字符串com.test.edu.personal.SomeException:这是一些错误:测试消息。我需要将字符串作为SomeException:这是一些错误。

I am having troubles with my code:

我的代码遇到了麻烦:

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))));

I am getting nal.SomeException: this is some - I am missing something here

我得到了nal.SomeException:这是一些 - 我在这里遗漏了一些东西

1 个解决方案

#1


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))

Returns

返回

SomeException: this is some error: test message

#1


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))

Returns

返回

SomeException: this is some error: test message