# question

## how to use BETWEEN Operator for negative values

We had one table, one of column contains negative and positive values, how can we get required data by using BETWEEN operator? Example we are using below syntax, SELECT * FROM FactTable WHERE Lats between 5 and -5 (edited by moderator to try to get the question readable...)
1 comment

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

·
0 Likes 0 ·

·
Your range is incorrect. There are no numbers greater than or equal to 5 and less than or equal to -5. Use the below instead. BETWEEN -5 AND 5
1 comment

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

·
To clarify @virtualjosh's answer, the `BETWEEN` operator works like this: SELECT * FROM FactTable WHERE Lats BETWEEN x AND y can be thought of as equivalent to: SELECT * FROM FactTable WHERE Lats >= x AND Lats
1 Like 1 ·
If your 5 and -5 are not constants, but rather variables, and you don't know beforehand which one is the bigger number of the two variables, you could use something like this: SELECT * FROM FactTable WHERE Lats BETWEEN CASE WHEN @variable1

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.