Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 replace text between curly bracket

Author  Topic 

kumar.sapidm
Starting Member

4 Posts

Posted - 2013-03-28 : 15:07:52
Hi guys,

How can I use replace statement in SQL query to replace/remove all the text inside the curly bracket and the curly bracket itself. I have many similar text like that with curly bracket in my database, can I use regular expression or something similar?

E.g. @DN = VALUE1!!{VALUE2}<VALUE3}
---> VALUE1!!<VALUE3}

From previous discussions i used this STUFF(DN, PATINDEX('%{ }%', DN), LEN(DN), '')
which is only giving NULL value.

Thanks

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-03-28 : 15:16:35
Here is a very crude way to do it. It doesn't tkae into account strings that do no have curly-braces, multiple curly-braces, etc..
DECLARE @DN VARCHAR(100) = 'VALUE1!!{VALUE2}<VALUE3}';

SELECT STUFF(@DN, CHARINDEX('{', @DN), CHARINDEX('}', @DN) - CHARINDEX('{', @DN) + 1, '')
Go to Top of Page

kumar.sapidm
Starting Member

4 Posts

Posted - 2013-03-29 : 08:29:49
Thanks a lot Lamprey, it worked.
Go to Top of Page

kumar.sapidm
Starting Member

4 Posts

Posted - 2013-03-31 : 13:34:11
can you plz help to get this.
from value1!!{value2}<value3> to only get
value1!!value3

thanks
Kumar
Go to Top of Page
   

- Advertisement -