gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 19:47:21 26 4
gpt4 key购买 nike

我有一个长字符串,字符串内有多个括号,我试图只获取字符串的最后一部分,但我已经实现了第一部分直到结束。

 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

关于database - 如何使用 MS SQL 仅查找带括号的字符串的最后一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51419486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com