• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Checking for alpha characters in a field

Hello All

Is it possible to select items in a SQL field that can only contain letters and nothing else, no numbers, special characters etc.

Many thanks
0
bostonste
Asked:
bostonste
  • 3
  • 3
2 Solutions
 
BrandonGalderisiCommented:
Yup...

This simple example shows how to use patindex to do it.


select 1
where patindex('%[^A-Z]%','aABaC')=0


select 1
where patindex('%[^A-Z]%','aAB1C')=0
0
 
BrandonGalderisiCommented:
just repalce 'aAB1C' or 'aABaC' with your column name.
0
 
Scott PletcherSenior DBACommented:

SELECT column, ...
FROM ...
WHERE column NOT LIKE '%[^a-z]%'
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
Scott PletcherSenior DBACommented:
Yes, I know that's annoying because of the NOT of a not (^), but really, there's no other easy way to do it :-) , at least AFAIK .
0
 
BrandonGalderisiCommented:
That does the same thing.
0
 
Scott PletcherSenior DBACommented:
Except that SQL would consider an index scan on that column for my code, since the column is not imbedded within a function call :-) .
0
 
bostonsteAuthor Commented:
EXCELLENT CHAPS
MANY THANKS
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now