According to microsoft documentation, the behavior of the ‘BETWEEN’ operator should be a closed interval both on the left and the right side, however, the following code:
SELECT CASE WHEN (1 BETWEEN 1 AND 2) THEN 'YEAH' ELSE 'NO' END AS [closed in the left],
CASE WHEN (1 BETWEEN 2 AND 1) THEN 'YEAH' ELSE 'NO' END AS [closed in the right]
shows otherwise. Can you reproduce it? What do you think?
The minimum value must always be specified first when using
BETWEEN. The documentation you cited indicates that:so your second CASE is actually testing: