I just realised, the following behaviour of SQL Server
SELECT
1
WHERE
' ' = ' '
Seemingly the string with just 1 space equals the string with 8 spaces. Can anyone explain, why that is and how i can compare empty strings?
I just realised, the following behaviour of SQL Server
SELECT
1
WHERE
' ' = ' '
Seemingly the string with just 1 space equals the string with 8 spaces. Can anyone explain, why that is and how i can compare empty strings?
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 WHERE and HAVING clause predicates and other Transact-SQL string comparisons. For example, Transact-SQL considers the strings 'abc' and 'abc ' to be equivalent for most comparison operations
use DataLength to compare in where clause.
To compare for empty string
SELECT *
FROM tableName
WHERE LTRIM(RTRIM(columnName))=''