Question

In an sql where condition there is a value like below

select * from tabl
where
code not between 'A00' and 'B99'

how does this work? till now i was thinking it works only with numeric and date

Was it helpful?

Solution 2

The BETWEEN operator will treat these as varchars, and apply its comparison rules accordingly:

BETWEEN returns TRUE if the value of test_expression is greater than or equal to the value of begin_expression and less than or equal to the value of end_expression.

SQL uses a list of the ASCII codes to determine which to sort where and in what order.

OTHER TIPS

The same way as ORDER BY works on varchar values.

Every char has its ASCII code and sort order, so every value can be compared by its ASCII code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top