|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, May 11, 2012 5:48 AM
Points: 5,
Visits: 37
|
|
I have been doing this operation with the LIKE operator in the past and have never thought of the PATINDEX operator. Both ways work well, i really can't find a performance difference between the two. Here are my two final functions. Thanks for putting this out there!
CREATE FUNCTION dbo.IsAlphaNumeric2( @input VARCHAR(MAX) ) RETURNS BIT AS BEGIN DECLARE @result BIT = 1 -- default result to true IF (@input LIKE '%[^a-Z,0-9,'' '']%') BEGIN SET @result = 0 -- found a non-alphanumeric character END
RETURN @result -- return result END
CREATE FUNCTION dbo.IsAlphaNumeric3( @input VARCHAR(MAX) ) RETURNS BIT AS BEGIN DECLARE @result BIT = 1 -- default result to true IF (PATINDEX('%[^a-Z,0-9,'' '']%', @input) > 0) BEGIN SET @result = 0 -- found a non-alphanumeric character END
RETURN @result -- return result END
-Eric
|
|
|
|