Could someone please explain me why does following query output '1'?
IF 'SQL ' LIKE 'SQL '
SELECT '1'
ELSE
SELECT '0'
Output:
1
Based on the clarification made in the link, I came to know, when we use LIKE
with VARCHAR
datatypes, it treats trailing whitespace as significant in the pattern (RHS) but not the match expression (LHS).
So, based on the above logic, in the above query, match expression 'SQL '
(LHS) is to be treated as 'SQL'
and then to be matched with pattern 'SQL '
(RHS) and should be resulting 0. But we are getting '1' instead of '0'.
But for the below cases, we are getting expected results.
IF 'SQL' LIKE 'SQL '
SELECT '1'
ELSE
SELECT '0'
IF 'SQL ' LIKE 'SQL'
SELECT '1'
ELSE
SELECT '0'
Output:
0
1