I hava a column name which is a varchar
I want to filter all results where name is an empty string...
where name <> ''
where Ltrim(RTrim(name)) <> ''
Standard behaviour in SQL-Server is that
' ' = ''
TRUE, because trailing spaces are ignored. From MSDN support:
SQL Server follows the ANSI/ISO SQL-92 specification (Section 8.2, , General rules #3) on how to compare strings with spaces. The ANSI standard requires padding for the character strings used in comparisons so that their lengths match before comparing them. The padding directly affects the semantics of
HAVINGclause predicates and other Transact-SQL string comparisons. For example, Transact-SQL considers the strings
'abc 'to be equivalent for most comparison operations.
The only exception to this rule is the
So, your condition
WHERE name <> '' should work fine, and not include any strings where there are only spaces.