I've just been experimenting with the "between" statement in TSQL the following code returns "true":
declare @Value as decimal
declare @Upper as decimal
declare @Lower as decimal
set @Value = 20.1
set @Lower = 10.0
set @Upper = 20.0
select
case
when @Value between @Lower and @Upper then 'true'
else 'false'
end as Result
If I change @Value to be 20.5, the result is "false", but 20.4 returns "true". It would appear that TSQL is using "banker's rounding" for decimal values.
If I change the variables to "money", I get the expected result, that is, @Value = 20.1 returns "false".
decimal
is equivalen todecimal(18,0)
- with 0 digits after the decimal point. So therefore, you're digits after the comma are shaved off* and your values20.0
and20.1
become identical -20
....