I have a long NVARCHAR variable where I need to replace some pattern like this:
DECLARE @data NVARCHAR(200) = 'Hello [PAT1] stackoverflow [PAT2] world [PAT3]'
I need to replace all [PAT%]
with a blank space to look like:
'Hello stackoverflow world'
How can I do this using T-SQL in SQL Server 2008?
I was searching in other questions, and I only found this, but it doesn't help me, because I don't need to preserve de original part of the string.
You may use this function for pattern replace. You can test it with this SQL-Fiddle demo to test.
Resource link.
+1 @Nico , I needed a function that will remove special charters from a string, so I adjusted your function a little bit to be able to do this:
Here is the function: