I am using SQL Server 2014 and I have the following T-SQL query:
select p9.[Name]
from [CleanGuestNames] p outer apply
(select replace(p.[Name], '@', '*') as [Name]) p1 outer apply
(select replace(p1.[Name], '&', '*') as [Name]) p2 outer apply
(select replace(p1.[Name], '\', '*') as [Name]) p3 outer apply
(select replace(p1.[Name], '?', '*') as [Name]) p4 outer apply
(select replace(p1.[Name], '/', '*') as [Name]) p5 outer apply
(select replace(p1.[Name], ':', '*') as [Name]) p6 outer apply
(select replace(p1.[Name], ';', '*') as [Name]) p7 outer apply
(select replace(p1.[Name], '.', '*') as [Name]) p8 outer apply
(select replace(p2.[Name], ',', '*') as [Name]) p9 ;
Codes above are supposed to replace all characters mentioned therein with a * in the [Name] column.
When I run the query, I still get records as follows from the [Name] column:
Alex / Sandrine SINNOF / VAN ACK
Peter / Jane KELLY
Expected Results:
Alex * Sandrine SINNOF * VAN ACK
Peter * Jane KELLY
What am I doing wrong here?
p1.[Name], notp1.[Name], thenp2.[Name], thenp3.[Name]. Though, personally, I would suggest just nesting theREPLACEfunctions. If you were on a fully supported version of SQL Server, thenTRANSLATEwould be a much better option.