且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在SQL中提取字符串的两个字符之间的所有数据?

更新时间:2023-02-04 15:02:05

BBB

BB

CCCCC

Hi Guys,

Please help me out to extract all the data between two particular characters in a column.

For example, I have data in a column data like,

"aaaaa( bb (asdads) bbb )"

And i need the output like,
"aaaaa"

Hint: Need to remove all the data in between "(" & ")" characters

Can anyone help me to get this produce this output in SQL.

What I have tried:

This query is not working properly as i expect,

SELECT SUBSTRING('aaaaa$bbb$bb$ccccc$ddddd',
CHARINDEX('$','aaaaa$bbbbb$ccccc')+1, 
CHARINDEX('$','aaaaa$bbbbb$ccccc',CHARINDEX('$','aaaaa$bbbbb$ccccc')+1) -
CHARINDEX('$','aaaaa$bbbbb$ccccc')-1) as My_String 

bbb


bb


ccccc