Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

IsAlphaNumeric Expand / Collapse
Author
Message
Posted Saturday, December 3, 2011 10:52 PM


Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, May 11, 2014 8:08 PM
Points: 5, Visits: 44
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
Post #1215935
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse