SQL Obfuscate Data Values

When working with client databases, the need may become important to garble (obfuscate) some data values such as a customer name, address lines, vendor name, or item number/description. This simple function can be created and then used in a Update statement to change the value of a fields. A couple of before/after examples for a customer name are shown below:

Orig: HAWK VALVE New:HoWK VoLVE
Orig: HONEYWELL PROCESS SOLUTIONS New: HeNEYWEski PRekESS SeLipaeNS
Orig: D & M TECHNOLOGIES, INC. New: th & M pEkHNeLeGaES, aNk.
Orig: ITF, INC. New: apF, aNk.


---------------------
-- Garble Function --
---------------------
-- Make a function to slightly garble the strings
IF (object_id('fn_Garble') is not null)
  drop function fn_Garble
go
create function fn_Garble
(
  @String varchar(255)
)  
returns varchar(255)
as
BEGIN
  select @String = replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(@String,'o','e'),'a','o'),'i','a'),'u','i'),'t','p'),'c','k'),'d','th'),'ee','e'),'oo','or'),'ll','ski')
  return @String
END
go


select Customername, dbo.fn_Garble(CustomerName)
from Customer

RESULTS:
HONEYWELL PROCESS SOLUTIONS	HeNEYWEski PRekESS SeLipaeNS