如何使用MS SQL仅找到带括号的字符串的最后一部分

数据库

我有一个长的字符串,字符串中有多个括号,我试图仅提取字符串的最后一部分,但是我已经达到了第一部分直到结尾。

 Alkyl acrylate-Styrene (or alpha-Methylstyrene) copolymer (Substances not 
 requiring notification is limited to the following: Copolymer of butyl 
 acrylate / styrene (It is limited that the polymer is insoluble in water, acid 
 and alkali, and the content of the components having molecular weight less 
 than 1,000 is 1% or less.))

我的查询:

SELECT  [RigNumSrc],[SubSRC],
case when  CHARINDEX(' (',[SubSRC])<>0  then LEFT ([SubSRC], charindex (' (', 
[SubSRC])-1)  
         when  CHARINDEX(' (',[SubSRC])=0 then [SubSRC] end as [chemnamesrc1]
 ,case when  CHARINDEX(' (',[SubSRC])<>0  then SUBSTRING([SubSRC], 
CHARINDEX(' 
(',[SubSRC]),LEN([SubSRC]))
end as synamesrc1 from xyztable

我的结果:

    (or alpha-Methylstyrene) copolymer (Substances not requiring notification 
    is limited to the following: Copolymer of butyl acrylate / styrene (It is 
    limited that the polymer is insoluble in water, acid and alkali, and the 
    content of the components having molecular weight less than 1,000 is 1% 
     or less.))

请只帮助我查找:

 (It is limited that the polymer is insoluble in water, acid 
 and alkali, and the content of the components having molecular weight less 
 than 1,000 is 1% or less.)
杀手皇后

尝试:

DECLARE @myString VARCHAR(MAX)='Alkyl acrylate-Styrene (or alpha-Methylstyrene) copolymer (Substances not requiring notification is limited to the following: Copolymer of butyl 
acrylate ( styrene (It is limited that the polymer is insoluble in water, acid and alkali, and the content of the components having molecular weight less than 1,000 is 1% or less.))'

SELECT CASE WHEN RIGHT(@myString,1) <> ')' THEN NULL ELSE REPLACE(RIGHT(@myString , CHARINDEX ('(' ,REVERSE(@myString))),'))',')') END 

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何获得仅包含POST响应的最后一部分的字符串?

仅使用SQL拉取字符串的一部分

如何找到子字符串字符串的一部分

如何使用VBa选择字符串的最后一部分?

如何使用preg_match提取找到的字符串的一部分?

在特定字符串保留部分字符串以在 SQL 中替换后,如何仅替换字符串的一部分?

如何在JavaScript中获取字符串的最后一部分?

如何分割字符串并获得最后一部分?

如何删除字符串的最后一部分?

如何在JavaScript中删除字符串的最后一部分?

如何动态替换字符串的最后一部分?

如何在C中删除字符串的最后一部分

分割字符串并使用C获取最后一部分

如何找到字符串的一部分并将其回显?

如何仅提取字符串的一部分

如何仅捕获匹配字符串的一部分?非捕获组

如何在laravel 5.2中仅显示字符串的一部分?

如何仅使字符串的一部分大写?

如何仅将字符串的一部分呈现为HTML

使用WriteLine仅将字符串的一部分写入文件

使用gsub或sub函数仅获取字符串的一部分?

仅使用字符串的一部分

使用gsub仅保留字符串的第一部分

使用sed仅更改子字符串的一部分

使用VLOOKUP Excel仅匹配输入字符串的一部分

更新列MS SQL中的一部分字符串

如何合并JSON值中的字符串,仅保留一部分字符串?

如何仅匹配Javascript中的字符串的一部分或包含的字符串

如何在SQL中将NULL连接为字符串的一部分