SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 replace text between curly bracket
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kumar.sapidm
Starting Member

USA
4 Posts

Posted - 03/28/2013 :  15:07:52  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 03/28/2013 :  15:16:35  Show Profile  Reply with Quote
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

USA
4 Posts

Posted - 03/29/2013 :  08:29:49  Show Profile  Reply with Quote
Thanks a lot Lamprey, it worked.
Go to Top of Page

kumar.sapidm
Starting Member

USA
4 Posts

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

thanks
Kumar
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000