Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 DIVISION BY ZERO ERROR on NULL VALUES

Author  Topic 

jennypretty
Yak Posting Veteran

96 Posts

Posted - 2004-11-03 : 11:03:46
Hello friends,
I tried to check values on A SELECT STMT but it showed errors:
"Divide by zero error encountered.
Warning: Null value is eliminated by ...."
SELECT EMP_ID,
ROUND(SALARY/(FULL_TIME_EMP+PART_TIME_EMP)) AS SALARY_RATE
FROM EMP;

Data from EMP table:
EMP_ID SALARY FULL_TIME_EMP PART_TIME_EMP
------ ------ ------------- -------------
001 2000 0 30000
002 0 40000 14000
003 50000 24000 20000
004 0 0 0
(THIS IS JUST A SAMPLE)

PLEASE HELP.
JENNY.

The stupid question is the question you don't ask.
www.single123.com

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2004-11-03 : 11:33:43
You have to decide what to do when
FULL_TIME_EMP+PART_TIME_EMP = 0
or when SALARY is null.

In the table is it ok that those columns allow null or are zero.
You can put constraints on the table to make sure the data is ok.

rockmoose
Go to Top of Page

jennypretty
Yak Posting Veteran

96 Posts

Posted - 2004-11-03 : 11:41:35
Is there any way that ignore the job when dividing by zero?
I meant, when divide by zero, it should return zero values.
Thanks.
please help.
Jenny.

The stupid question is the question you don't ask.
www.single123.com
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-11-03 : 11:46:34
Jenny -- Do you know how to use CASE ?? I'm pretty sure we've helped you with many problems in the last month or so using the CASE function. It might be useful here ..... Do you have any ideas yet?



- Jeff
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-11-03 : 13:33:39
"I meant, when divide by zero, it should return zero values."

Why? Are you sure that would be safe (in the circumstances of this specific data)?

In most cases I consider divide by error to be a problem with validation fo the data, or the business logic.

Kristen
Go to Top of Page
   

- Advertisement -