Tuesday, October 23, 2018

SQL replace all characters between two strings

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

Solution :
declare @str varchar(100)
select @str='This is Sql testing Text [23/10/2018 12:23 - admin]'
select stuff(@str,patindex('%(%',replace(@str,'[','(')),LEN(@str),'')

Result :  This is testing Text 

No comments:

Post a Comment

Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...