How do include space in like statement SQL

9.9k views Asked by At

I am wondering how to query any number of characters then a space then any number of characters then a comma?

I am looking for last names in a table that contains a space before the comma. For example, they query would return SMITH III, Richard.

Thanks in advance

2

There are 2 answers

0
Tingo On

The % symbol is used to denote a wildcard, you can use it like this:

SELECT * FROM [myTable] WHERE [myField] LIKE '% %,%'
0
Karl Kieninger On

In SQL Server you may find performance better with PATINDEX.

SELECT * FROM [myTable] WHERE PATINDEX('% %,%',[myField]) > 0