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 Check Binary Values for symbols gandikk CA Products 3 Tue Mar 21, 2017 5:11 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts To display values of multiple rows in... vinu78 DB2 2 Thu Mar 09, 2017 1:20 pm
No new posts Replacing same string with different ... vickey_dw DFSORT/ICETOOL 6 Wed Feb 22, 2017 10:44 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm


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