Home > front end >  SQL Server : how to check if a string contains letters only?
SQL Server : how to check if a string contains letters only?

Time:07-16

I have a column of type nvarchar that looks like this:

col
--------
123hello45
12345
hello

Expect output

col
--------
hello

Azure Synapse doesn't support regular expression. How can I find out if the rows contains letters only?

CodePudding user response:

We can use SQL Server's enhanced LIKE operator here:

SELECT col
FROM yourTable
WHERE col NOT LIKE '%[^A-Za-z]%';

The logic here is any col value which does not have one or more non letter characters therefore must be only letters.

  • Related