Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Function to Check Alphabat

Author  Topic 

AsimKhaliq
Yak Posting Veteran

94 Posts

Posted - 2003-12-06 : 12:43:51
Hi
I have to check that left(Field,4) is alphabat, is there any function or method to check it.
For Example we use IsNumeric(Field) for number. So are there any functions for character
Thanks in Advance

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-12-06 : 13:01:12
PATINDEX('%[^a-z]%', @YourString)

If that returns 0, all characters are between a and z. otherwize, there's at least one that's not.

- Jeff
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-12-09 : 10:15:33
To expand on Jeff's post, and to make it act like the other function you mention, and because it seems to be handy anyway (and why ms didn't incluse it...)


CREATE FUNCTION IsAlphabetic
(@String varchar(8000))
RETURNS int
AS
BEGIN
DECLARE @rc int
SELECT @rc = CASE WHEN PATINDEX('%[^a-z]%', @String) = 0 THEN 1 ELSE 0 END
RETURN @rc
END

SELECT dbo.IsAlphabetic('abc')



Happy interogating...



Brett

8-)
Go to Top of Page
   

- Advertisement -