Data scrubbing using SQL functions for SQL Server
Many a times, it is required to scrub the data before it is used in development environments as the data may be sensitive and cannot be shared with the vendors. The below SQL functions can be used to scrub the data. --Creating the User defined function CREATE FUNCTION getRandomText(@sLength TINYINT) RETURNS VARCHAR(10) AS BEGIN DECLARE @counter TINYINT DECLARE @nextChar CHAR(1) DECLARE @randomString VARCHAR(50) SET @sLength=10 SET @counter = 1 SET @randomString = '' WHILE @counter <= @sLength BEGIN SELECT @nextChar = CHAR(ROUND((SELECT r FROM getRand) * 93 + 33, 0)) IF ( (ASCII(@nextChar) between 65 and 90) or (ASCII(@nextChar) between 97 and 122) ) BEGIN SELECT @randomString = @randomString + @nextChar SET @counter = @co