如何使用 MS SQL 仅查找带括号的字符串的最后一部分
How to find only last part of string with brackets using 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
我有一个长字符串,字符串内有多个括号,我试图只获取字符串的最后一部分,但我已经实现了第一部分直到结束。
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