I’m creating a simple procedure in SQL Server as below.
DECLARE @num int;
SET @num = 5;
SELECT @num WHERE @num BETWEEN 1 AND 10;
SELECT @num WHERE @num BETWEEN 10 AND 1;
If you run this, the first select statement gives you 5 and the second one returns nothing.
I am confused as to why this is, as both cases should return true as 5 is between 10 and 1 as well as 1 and 10.
Is there is a reason why the BETWEEN 10 AND 1 line defies logic?
Thanks
This is what the standard (was decided to be) for SQL.
stands for
See page 211 of: SQL-92 specifications (a copy of a review draft)
The only RDBMS I know that is away from the standard (and follows your logic) is MS-Access.