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 best solutions below

0
On

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

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

In SQL Server you may find performance better with PATINDEX.

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