Script: Remove Ghost Characters


/*
Script By: Aasim Abdullah
For: ReConnectSQL and http://www.connectsql.com
Purpose: to remove special characters from data
*/
Create FUNCTION [dbo].[RemoveGhostCharacters] (@s varchar(MAX)) returns varchar(MAX)
with schemabinding
BEGIN
if @s is null
return null
declare @s2 varchar(MAX)
set @s2 = ''
declare @l int
set @l = len(@s)
declare @p int
set @p = 1
while @p <= @l begin
declare @c int
set @c = ascii(substring(@s, @p, 1))
if @c between 32 and 126 OR @C BETWEEN 156 AND 157
set @s2 = @s2 + char(@c)
set @p = @p + 1
end
if len(@s2) = 0
return null
return @s2
END
GO

Continue reading “Script: Remove Ghost Characters”

Advertisements