Skip to content

Instantly share code, notes, and snippets.

@darth-veitcher
Created April 14, 2014 10:17
Show Gist options
  • Save darth-veitcher/10635120 to your computer and use it in GitHub Desktop.
Save darth-veitcher/10635120 to your computer and use it in GitHub Desktop.
CREATE FUNCTION dbo.CleanString (
@SomeText VARCHAR(8000)
)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @return VARCHAR(8000) = ''
DECLARE @position int = 1
WHILE @position <= DATALENGTH(@SomeText)
BEGIN
IF ASCII(SUBSTRING(@SomeText, @position, 1)) BETWEEN 32 AND 127
SET @return = @return + SUBSTRING(@SomeText, @position, 1)
SET @position = @position + 1
END
RETURN @return
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment