Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wildcard characters sql only alphabet characters

I need to create a rule only for alphabet characters

i used the following Wildcard character sequences but didn't work !

LIKE '[A-Za-z]'

LIKE 'a-z'

LIKE 'A-Za-z'

like image 230
Sudantha Avatar asked Feb 06 '11 14:02

Sudantha


People also ask

How do I get only characters in a string in SQL?

SQL Server LEFT() Function The LEFT() function extracts a number of characters from a string (starting from left).

What is like %% in SQL?

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.

How do I select only alpha characters in SQL?

How do I select only alpha characters in SQL? SELECT productname, SUBSTRING(Name,1,ISNULL(NULLIF(PATINDEX('%[^A-Za-z. ''0-9]%',LTRIM(RTRIM(productname))),0)-1,LEN(productname))) AS noSpecials.


1 Answers

Double negative like

WHERE
  SomeCol NOT LIKE '%[^a-z]%'

Ignoring the first NOT, this means "match any character not in the range a to z".

Then, you reverse using the first NOT which means "don't match any character not in the range a to z"

Edit, after comment

LIKE '%[a-z]%' means "find any single character between a-z. So 111s222 is matched for example because s matches in this like.

like image 141
gbn Avatar answered Oct 19 '22 16:10

gbn