Remove Non Alphanumeric Characters

by Amol 20. July 2012 08:45

SQL Query to remove non alphanumeric characters

CREATE FUNCTION dbo.RemoveNonAlphaNumericCharacters

(

      @Str nvarchar(255)

)

RETURNS int

AS

BEGIN

 

      DECLARE @Result varchar(255)

      SET @Result = 1

 

      DECLARE @nchar nvarchar(1)

      DECLARE @position int

 

      SET @position = 1

      WHILE @position <= LEN(@Str)

      BEGIN

 

            SET @nchar = SUBSTRING(@Str, @position, 1)

            IF (ASCII(@nchar) between 32 and 128)

            BEGIN

                SET @Result = 1

            END

            ELSE

            BEGIN

                SET @Result = 0

                BREAK

            END

            SET @position = @position + 1

      END

 

      RETURN @Result

END 

Tags: ,

SQL Server Scripts

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Category

Recent Posts

Tag cloud