Search code examples
sqlsql-serverazure-synapse

How to check if a string contains letters only?


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?


Solution

  • 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.