How to write a query with the ‘like’ operator that matches only text fields that contain multiple whitespaces and nothing more.
E.g. ‘ ‘,’ ‘, ‘ ‘, etc. are string that should be found.
‘ text ‘, ‘text ‘ — should not be included in the result set
(Sql Server 2008 R2)
How to write a query with the ‘like’ operator that matches only text fields
Share
In SQL Server, leading and trailing spaces are ignored for string comparisons.
That means you can just compare to an empty string to get your desired result:
WHERE SomeVarchar = ''This will evaluate true even if SomeVarChar is a series of 20 spaces: