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 replace a decimal value with spaces

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
mahesh pillai

New User


Joined: 04 Oct 2011
Posts: 6
Location: india

PostPosted: Wed Jun 17, 2015 8:13 pm    Post subject: How to replace a decimal value with spaces
Reply with quote

Hi Friends,

I have to extract a report from one of the database table. I have an issue with one of the column which is having a decimal value.

The user wants that if the value of this field is '0' then it should be reflected as 'SPACES' in the final report.

The datatype of this column is DECIMAL(9,2). I tried converting this column to character first using CHAR function and then trying to REPLACE the values but in vain. I am creating the report using the STRIP function and tried using the belwo query:

STRIP(CHAR(REPLACE(COLUMN NAME,'0.00',' ')))
Back to top
View user's profile Send private message

Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2134
Location: UK

PostPosted: Thu Jun 18, 2015 2:10 am    Post subject:
Reply with quote

Why not do it in your program instead of your SQL?
Back to top
View user's profile Send private message
mahesh pillai

New User


Joined: 04 Oct 2011
Posts: 6
Location: india

PostPosted: Thu Jun 18, 2015 6:48 am    Post subject:
Reply with quote

The user doesn't want us to write a new program but to do it via queries.
We don't have funding for the same.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1306
Location: Israel

PostPosted: Thu Jun 18, 2015 7:21 pm    Post subject:
Reply with quote

This almost work:
Code:
CASE WHEN YourColumn = 0
  THEN ' '
  ELSE CAST(YourColumn AS CHAR(12))
END


I say almost because numbers become left justified and "0.5" shows as ".5"
but it's a start...
Back to top
View user's profile Send private message
mahesh pillai

New User


Joined: 04 Oct 2011
Posts: 6
Location: india

PostPosted: Fri Jun 19, 2015 3:33 pm    Post subject:
Reply with quote

Hi Marso,

Thanks a lot for your help here. This has worked perfectly fine and report output is as expected.

Thanks again.
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 Add week number to a file name or rep... tejdeep0274 JCL & VSAM 2 Thu Jan 03, 2019 6:49 am
No new posts Comparing Signed Packed decimal and p... Virendra Shambharkar SYNCSORT 2 Wed Nov 14, 2018 9:37 am
No new posts Silly question maybe - REPLACE member... Cloink TSO/ISPF 15 Thu Oct 25, 2018 6:38 pm
No new posts Replace comp-3 field value to comp-3 ... dharmaraok DFSORT/ICETOOL 5 Fri Sep 14, 2018 3:46 pm
No new posts RPG II Problem with unsigned Packed d... Andi1982 All Other Mainframe Topics 6 Tue Sep 11, 2018 6:11 pm

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