Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to divide two decimal values in a SELECT query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: How to divide two decimal values in a SELECT query
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    Post subject:
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    Post subject: Reg: Query
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    Post subject:
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    Post subject: Reg: query
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject: Reg: query
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us