DBA > Job Interview Questions > Sybase Interview Questions and Answers

Divide by zero and nulls in Sybase

More DBA job interview questions and answers at http://dba.fyicenter.com/Interview-Questions/

(Continued from previous question...)

Divide by zero and nulls in Sybase

During processing, if a divide by zero error occurs you will not get the answer you want. If you want the result set to come back and null to be displayed where divide by zero occurs do the following:

1. select * from total_temp
2. go
field1 field2
----------- -----------
10 10
10 0
10 NULL

(3 rows affected)
1. select field1, field1/(field2*convert(int,
substring('1',1,abs(sign(field2))))) from total_temp
2. go
field1
----------- -----------
10 1
10 NULL
10 NULL

(Continued on next question...)

Other Job Interview Questions