In select statement how to avoid divide by zero in MapBasic:

select (col1/col2) "result"

If col2 is 0 it returns null.

How to use ISNULL or something in mapbasic?

  • Usually, any selection based on a quotient can be replaced by a selection based on a product that is algebraically equivalent to the quotient for nonzero denominators (and creates no divide-by-zero problems). What specifically is your select statement? – whuber Nov 28 '15 at 21:08
  • @whuber I added 0.01 to divider and it solved the issue. In my situation I changed col2 (col2+0.01).I wondered if any options isnull,default or something exist. – Burak Karasoy Nov 28 '15 at 21:22
  • 1
    Select (col1/col2) where col2 != 0 ? – user1269942 Nov 29 '15 at 2:48
  • As stated in the comment above, you could add a condition to the query which would filter out those records where col2 = 2, or in other words only will keep those records where col2 <> 0 – Peter Horsbøll Møller Nov 30 '15 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.