IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Replacing charactrers


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
srj1957

New User


Joined: 15 Dec 2005
Posts: 72
Location: RALEIGH NC, USA

PostPosted: Fri Jul 12, 2013 1:24 am
Reply with quote

I have a column that can contain 4 different types of Account number.
e.g.
ACCT_NUM
000001107028
1107028
A0001107028
M1107028

I want to remove leading zeros
    remove leading zeros
    Remove the 'A'
    Remove the 'M'

so that I end up with the 4 account numbers numbers looking like this

1107028
1107028
1107028
1107028

I have tried this
Code:

SELECT COL_A,
   REPLACE(
   REPLACE(
   REPLACE(ACCT_NUM
   ,'0','')
   ,'M','')
   ,'A','')AS X
from table

and I get this
11728
11728
11728
11728

I want to remove only LEADING ZEROES not replace all the zeros...

Any suggestions would be greatly appreciated on how to solve this...
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Fri Jul 12, 2013 10:14 am
Reply with quote

Hi srj1957,

Try like below,
Code:
SELECT STRIP('000001107028', L,'0') FROM SYSIBM.SYSDUMMY1;


Thanks,
Sushanth
Back to top
View user's profile Send private message
Siva SS

New User


Joined: 08 Jul 2013
Posts: 1
Location: India

PostPosted: Fri Jul 12, 2013 11:03 am
Reply with quote

You might also want to try:
Code:
 SELECT TRIM(LEADING '0' FROM '000001107028') FROM SYSIBM.SYSDUMMY1;
Back to top
View user's profile Send private message
srj1957

New User


Joined: 15 Dec 2005
Posts: 72
Location: RALEIGH NC, USA

PostPosted: Fri Jul 12, 2013 5:03 pm
Reply with quote

Thanks for your replies.... I have tried those before, they remove ONLY the zero, the main issue is the ones with the ALPHA characters at the beginning

A0001107028
M1107028

to look like this

1107028
1107028

I having trouble finding a sloution...
Back to top
View user's profile Send private message
srj1957

New User


Joined: 15 Dec 2005
Posts: 72
Location: RALEIGH NC, USA

PostPosted: Fri Jul 12, 2013 5:16 pm
Reply with quote

Thanks for your replies....

NOTE : I mis-stated in my original question icon_rolleyes.gif
I didn't mean to say that I get this.. I meant to say I WANT this.
1107028
1107028
1107028
1107028


I have tried those before, they remove ONLY the zero, the main issue is the ones with the ALPHA characters at the beginning

A0001107028
M1107028

I want the result to look like this...
1107028
1107028



I having trouble finding a sloution...
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri Jul 12, 2013 6:05 pm
Reply with quote

If these are account numbers - are they table keys?
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Fri Jul 12, 2013 6:15 pm
Reply with quote

Try to RIGHT justify when select and SUBSTR to pick last 10 charecters
Back to top
View user's profile Send private message
srj1957

New User


Joined: 15 Dec 2005
Posts: 72
Location: RALEIGH NC, USA

PostPosted: Fri Jul 12, 2013 6:44 pm
Reply with quote

Nic - No they are not keys

P-B ..I want to lose all leading zeros
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Fri Jul 12, 2013 8:06 pm
Reply with quote

Hi,

Try below query, I have just combined solutions provided in earlier posts

Code:
SELECT TRIM (LEADING '0' FROM (REPLACE(REPLACE('A0001107028','A','0'),'M','0'))) FROM SYSIBM.SYSDUMMY1;


Reagrds,
Chandan
Back to top
View user's profile Send private message
srj1957

New User


Joined: 15 Dec 2005
Posts: 72
Location: RALEIGH NC, USA

PostPosted: Fri Jul 12, 2013 9:37 pm
Reply with quote

Thanks for the suggestions... I came up with this that works


Code:
SELECT COL_A,
CASE SUBSTR(COL_A,1,1)
WHEN 'A' THEN TRIM(L '0' FROM SUBSTR(COL_A,2,19))
WHEN 'M' THEN TRIM(L '0' FROM SUBSTR(COL_A,2,19))
WHEN '0' THEN TRIM(L '0' FROM COL_A)
ELSE COL_A END
FROM   TABLE
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts Finding record and replacing with val... DFSORT/ICETOOL 3
No new posts Replacing character string in file th... JCL & VSAM 9
No new posts Replacing PDSMAN with PDSFAST JCL & VSAM 10
No new posts JCL for replacing code in Cobol JCL & VSAM 7
Search our Forums:

Back to Top