Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 6968
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: 6968
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 Extend the decimal values in DIVISION Balaryan DFSORT/ICETOOL 3 Thu Oct 05, 2017 4:05 pm
No new posts HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts Working with hex values in Filemanage... Emile Straker IBM Tools 0 Tue Sep 12, 2017 1:42 am
No new posts DB2 NULL Values display V S Amarendra Reddy DB2 3 Thu Sep 07, 2017 6:59 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us