Is there any SQL statements to replace everything in a string with an 'X'. The strings aren't all the same length so it makes it a bit tricky. I haven't been able to find anything that does this except the function below but it takes a long time when I pass in 'a-z0-9' since I have to search on all of those but I really just want to replace everything no matter what it is.
[dbo].[cfn_StripCharacters]
(
@String NVARCHAR(MAX),
@MatchExpression VARCHAR(255)='a-z0-9'
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
SET @MatchExpression = '%['+@MatchExpression+']%'
WHILE PatIndex(@MatchExpression, @String) > 0
SET @String = Stuff(@String, PatIndex(@MatchExpression, @String), 1, 'X')
RETURN @String
For example the data column looks like this and I want to replace the whole string with x's:
975g -> XXXX
ryth5 -> XXXXX
1234vvsdf5 -> XXXXXXXXXX
test1234 -> XXXXXXXX