View previous topic :: View next topic
|
Author |
Message |
muthukannan
New User
Joined: 03 Aug 2006 Posts: 42 Location: Chennai
|
|
|
|
Hi,
Can someone please explain how to divide two decimal values in a SELECT query. When i did so i got a sql code as -802.
If you can please post a sample query also.
Thanks in advance.
Thanks,
Mk |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
muthukannan,
show us your query. If you had looked up -802, you would find that the reasons include data - divide by zero -
any SQL manual will provide an example.
SELECT A
FROM TABLE
WHERE B/4 > C |
|
Back to top |
|
|
muthukannan
New User
Joined: 03 Aug 2006 Posts: 42 Location: Chennai
|
|
|
|
Hi,
The following is the sample query.
select ((cola/colb) * 100) from table
In this cola and colb are decimal
Thanks,
Mk |
|
Back to top |
|
|
amitava Warnings : 1 Active User
Joined: 30 Oct 2005 Posts: 186 Location: India
|
|
|
|
Hey muthukannan, U r doing something wrong in the query. The query should work and also for clarifying the scenario I checked in my system. My query was like -
Code: |
select (salary/empno) * 100 from emp
;
|
And it worked. For your information, salary is a decimal and empno is an integer field. Please check the fields otherwise it should work. |
|
Back to top |
|
|
muthukannan
New User
Joined: 03 Aug 2006 Posts: 42 Location: Chennai
|
|
|
|
Hi Amitava,
Can you please use the denominator also as a decimal value.
can you please check that and tell me.
Thanks
Mk |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
I would utilize a WHERE clause to exclude colb = 0. If either cola or colb could be NULL, I would include that condition in my WHERE clause also. |
|
Back to top |
|
|
amitava Warnings : 1 Active User
Joined: 30 Oct 2005 Posts: 186 Location: India
|
|
|
|
Hey man! When it is working with integer, it should work with decimal also! However, I have checked also and it is working fine. |
|
Back to top |
|
|
amitava Warnings : 1 Active User
Joined: 30 Oct 2005 Posts: 186 Location: India
|
|
|
|
Wah! dbzTHEdinosauer has given a very good suggestion just like a Dinosauer. Hey I am joking! Pls don't mind. Yop muthukannan check whether the colb is not zero and not null. Only then ur query can not work. |
|
Back to top |
|
|
muthukannan
New User
Joined: 03 Aug 2006 Posts: 42 Location: Chennai
|
|
|
|
Hi Amitava,
The query is working fine.
Thanks,
Mk |
|
Back to top |
|
|
|