IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to divide two decimal values in a SELECT query


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
muthukannan

New User


Joined: 03 Aug 2006
Posts: 42
Location: Chennai

PostPosted: Thu Aug 30, 2007 10:29 am
Reply with quote

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 icon_smile.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Aug 30, 2007 12:41 pm
Reply with quote

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
View user's profile Send private message
muthukannan

New User


Joined: 03 Aug 2006
Posts: 42
Location: Chennai

PostPosted: Thu Aug 30, 2007 3:51 pm
Reply with quote

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
View user's profile Send private message
amitava
Warnings : 1

Active User


Joined: 30 Oct 2005
Posts: 186
Location: India

PostPosted: Thu Aug 30, 2007 4:28 pm
Reply with quote

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
View user's profile Send private message
muthukannan

New User


Joined: 03 Aug 2006
Posts: 42
Location: Chennai

PostPosted: Thu Aug 30, 2007 4:31 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Aug 30, 2007 4:39 pm
Reply with quote

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
View user's profile Send private message
amitava
Warnings : 1

Active User


Joined: 30 Oct 2005
Posts: 186
Location: India

PostPosted: Thu Aug 30, 2007 4:43 pm
Reply with quote

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
View user's profile Send private message
amitava
Warnings : 1

Active User


Joined: 30 Oct 2005
Posts: 186
Location: India

PostPosted: Thu Aug 30, 2007 4:46 pm
Reply with quote

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
View user's profile Send private message
muthukannan

New User


Joined: 03 Aug 2006
Posts: 42
Location: Chennai

PostPosted: Thu Aug 30, 2007 5:57 pm
Reply with quote

Hi Amitava,

The query is working fine. icon_smile.gif


Thanks,
Mk
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
Search our Forums:

Back to Top