Hi guys can someone help me to write this?
DECLARE @STR VARCHAR(55) = 'Name';
SELECT // SOME LOGIC
RESULT => 'NXXE'
I would like this logic to be generalized to replace every string except the first and last character.
if dynamic data masking is not an answer you can use query below :
DECLARE @str VARCHAR(100) = 'yourstring'
SELECT UPPER(LEFT(@str,1) + REPLICATE('x',LEN(@str) -2)+ RIGHT(@str,1))
This is what you want
DECLARE @STR VARCHAR(55) = 'Name';
declare @i int
Set @i = 0
while @i <= len(@STR )
begin
select @i = @i + 1
if(@i>1 AND @i<len(@STR ))
select @STR = STUFF(@STR , @i, 1, 'X')
END
SELECT @STR