Reputation: 1
I have a situation where i need to replace the entire text and the square bracket with a single charecter inside stored procedure. ( Iam using Sql Server 2012).
Eg:->
Let us consider that i have a text san[123456dd]text
i just wanted to replace all the text inside the square bracket and square bracket itself with another charecter say 'X'
Here, My end result should be sanXtext.
Could anyone help me regarding this?
Upvotes: 0
Views: 2447
Reputation: 69564
DECLARE @String VARCHAR(1000) = 'san[123456dd]text'
SELECT LEFT(@String, CHARINDEX('[', @String)-1) +'X' +
RIGHT(@String, CHARINDEX(']', REVERSE(@String))-1)
Result: sanXtext
Upvotes: 1