MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Truncate function

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
schintala
Beginner


Joined: 18 May 2005
Posts: 108
Topics: 31
Location: USA

PostPosted: Wed Aug 10, 2005 1:30 pm    Post subject: Truncate function Reply with quote

Is there any DB2 function to truncate the decimal values up to 2 or so?
I have the below query which I need the value till 2nd precision in decimal value.

Code:
SELECT COUNT1,COUNT2,COUNT3,COUNT4,COUNT5,COUNT6,COUNT7,                 
(DECIMAL((COUNT2*100),10,3)/(COUNT2+COUNT3+COUNT4+COUNT5+COUNT6+COUNT7))
AS PERCENTAGE                                                           
FROM IDTOUT01.ITOUREPORT WHERE SESSIONID='20050810132342243129'         


Any ideads?
Back to top
View user's profile Send private message
Cogito-Ergo-Sum
Advanced


Joined: 15 Dec 2002
Posts: 637
Topics: 43
Location: Bengaluru, INDIA

PostPosted: Wed Aug 10, 2005 2:07 pm    Post subject: Reply with quote

Maybe this?
Code:
SELECT DECIMAL(ROUND(1234.5694,2),8,2) FROM SYSIBM.SYSDUMMY1 ;


Output:
Code:

       COL1
-----------
    1234.57

_________________
ALL opinions are welcome.

Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Wed Aug 10, 2005 2:19 pm    Post subject: Reply with quote

Schintala,

Please provide us with the sample input and desired output. I think you need to use the CAST function. btw are you able to solve the problem posted here?

http://www.mvsforums.com/helpboards/viewtopic.php?t=4635


Cogito,

ROUND rounds the decimal portion and I don't think schintala wanted to round the data.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
schintala
Beginner


Joined: 18 May 2005
Posts: 108
Topics: 31
Location: USA

PostPosted: Wed Aug 10, 2005 2:57 pm    Post subject: Reply with quote

Thank you very much for your replies. I tried using ROUND and TRUNCATE. But no luck. I am getting as below.


Code:
COUNT4       COUNT5       COUNT6       COUNT7          PERCENTAG
------  -----------  -----------  -----------  -----------------
  1766         1028         1217          882            23.3600
  1766         1028            -          882                   
  1001          718          705          445            24.6700
  1001          718          705          445            24.6700
  1647          972          962        10901            11.3600
  9289         5904         6228         4710            24.1500
  1647          972          962        10901            11.3600
  9289         5904         6228         4710            24.1500


I need the data in percentage column as 24.67, 11.36, 24.15, 11.36 etc.
My query like this.

Code:
SELECT COUNT1,COUNT2,COUNT3,COUNT4,COUNT5,COUNT6,COUNT7,                  TRUNCATE((DECIMAL((COUNT2*100),10)/(COUNT2+COUNT3+COUNT4+COUNT5+COUNT6 
        +COUNT7)),2)                                                     
AS PERCENTAGE                                                           
FROM IDTOUT01.ITOUREPORT;                                               
Back to top
View user's profile Send private message
SureshKumar
Intermediate


Joined: 23 Jan 2003
Posts: 211
Topics: 21

PostPosted: Wed Aug 10, 2005 3:07 pm    Post subject: Reply with quote

Schintala,
Cogito solution should be ok without the ROUND option,
SELECT DECIMAL((1234.5694),8,2)
, DECIMAL(ROUND(1234.5694,2),8,2)
FROM SYSIBM.SYSDUMMY1 ;

COL1 COL2
----------- -----------
1234.56 1234.57
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group