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)
 checking if a value is a letter in the alphabet

Author  Topic 

zubair
Yak Posting Veteran

67 Posts

Posted - 2004-02-25 : 09:50:48
Hi i'm passing in a value into a stored proc. What i want is to now do a check in the stored procedure before an insertion that the value passed to me is aletter i.e can be any letter between A to Z.

Also it must be only one letter in length. Can't be more than one like AZ etc but ONLY A

Can anyone help me on how to do this?

Thanks

SamC
White Water Yakist

3467 Posts

Posted - 2004-02-25 : 09:52:49
IF LEN(@Parm1) = 1 AND 'a' <= @Parm1 AND @Parm1 <= 'z' BEGIN

END
Go to Top of Page

raymondpeacock
Constraint Violating Yak Guru

367 Posts

Posted - 2004-02-25 : 10:41:38
Or
If LEN(@Parm1)=1 AND @Parm1 LIKE '[a-z]'

END



Raymond
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-25 : 11:11:57
I like it


DECLARE @Parm1 varchar(8000)

SELECT @Parm1 = 'A'
SELECT 'TRUE' WHERE LEN(@Parm1)=1 AND @Parm1 LIKE '[a-z]'

SELECT @Parm1 = 'Z'
SELECT 'TRUE' WHERE LEN(@Parm1)=1 AND @Parm1 LIKE '[a-z]'

SELECT @Parm1 = 'AA'
SELECT 'TRUE' WHERE LEN(@Parm1)=1 AND @Parm1 LIKE '[a-z]'

SELECT @Parm1 = '*'
SELECT 'TRUE' WHERE LEN(@Parm1)=1 AND @Parm1 LIKE '[a-z]'





Brett

8-)
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-02-25 : 11:34:12
quote:
Originally posted by raymondpeacock

Or
If LEN(@Parm1)=1 AND @Parm1 LIKE '[a-z]'

END



Raymond



why not just
@Parm1 LIKE '[a-z]'

--************************************************
DECLARE @Parm1 varchar(8000)

SELECT @Parm1 = 'A'
SELECT 'TRUE' WHERE @Parm1 LIKE '[a-z]'

SELECT @Parm1 = 'Z'
SELECT 'TRUE' WHERE @Parm1 LIKE '[a-z]'

SELECT @Parm1 = 'AA'
SELECT 'TRUE' WHERE @Parm1 LIKE '[a-z]'

SELECT @Parm1 = '*'
SELECT 'TRUE' WHERE @Parm1 LIKE '[a-z]'



Duane.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-25 : 11:39:07
Sure enough.....



Brett

8-)
Go to Top of Page

zubair
Yak Posting Veteran

67 Posts

Posted - 2004-02-25 : 13:03:43
Thanks for all the help guys!
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2004-02-25 : 14:54:33
Occam at work.

Can anyone else remove another character from the condition? I think not!
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-25 : 16:15:26
quote:
Originally posted by SamC

Occam at work.



?

are you drooling from too many martinis (like, if that were possible)

(Oh...the too many martinis part)





Brett

8-)
Go to Top of Page

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-02-25 : 17:06:40
quote:
Originally posted by SamC

Occam at work. Can anyone else remove another character from the condition? I think not!

@P LIKE '[a-z]'

Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2004-02-25 : 17:17:47
Zubari,

Shouldn't this be a CHECK constraint on the column itself? You should be trying to stick as many business rules into the table definition itself...

DavidM

"SQL-3 is an abomination.."
Go to Top of Page
   

- Advertisement -