T-SQL Tutorial

SQL Check if string contains letters


Check if string contains letters

To check if string contains letters uses the operator LIKE with the following regular expression '[A-Za-z]%'.

Return all rows

DECLARE @MyVariable table (name varchar(250));
INSERT INTO @MyVariable(name) values ('abcABCdef');
INSERT INTO @MyVariable(name) values ('111');
INSERT INTO @MyVariable(name) values ('ab5cABCdef2');
SELECT * FROM @MyVariable;
GO

Result:

abcABCdef

111

ab5cABCdef2

Return rows that contains letters

DECLARE @MyVariable table (name varchar(250));
INSERT INTO @MyVariable(name) values ('abcABCdef');
INSERT INTO @MyVariable(name) values ('111');
INSERT INTO @MyVariable(name) values ('ab5cABCdef2');
SELECT * FROM @MyVariable WHERE name LIKE '[A-Za-z]%';
GO

Result:

abcABCdef

ab5cABCdef2