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
 

 

Function-To find only starting Numbers from a String

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

Senior Member


Joined: 21 Sep 2010
Posts: 1696
Location: NY,USA

PostPosted: Sat Sep 06, 2014 2:13 am    Post subject: Function-To find only starting Numbers from a String
Reply with quote

I have a column which contains Address and I need only starting number ( St Number alone ) , the expections is
e.g. input data
'123ABC'
Output
123

I have tried below query and it works fine with one restriction.

Code:
select Replace('123ABC',(Select Replace(Replace(Replace(Replace(Replace(Replace(Replace
        (Replace(Replace(Replace('123ABC','0',''),'1',''),'2',
        ''),'3',''),'4',''),'5',''),'6',''),'7',''),'8',''),'9','')     
        from sysibm.sysdummy1 ) ,'') from sysibm.sysdummy1


Restriction:
If I get '123ABC1' then I do not need the last digit (1) but above query would return 1231 and I need just 123.

I know a UDF can be created for this but,I am looking for any SQL which does without a UDF.
Back to top
View user's profile Send private message

Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1696
Location: NY,USA

PostPosted: Sat Sep 06, 2014 2:37 am    Post subject:
Reply with quote

I have tried below as well but could not be able get over the above restriction,

Code:
select cast(
        replace(
         translate('123ABC1',repeat('#',26),'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'),'#','')as integer ) as Streetnum
from sysibm.sysdummy1
Back to top
View user's profile Send private message
Rohit Umarjikar

Senior Member


Joined: 21 Sep 2010
Posts: 1696
Location: NY,USA

PostPosted: Sat Sep 06, 2014 2:56 am    Post subject:
Reply with quote

I learned to know lately that there will always be a space after the street number e.g. '123 ABC' so I tried below query and it is working fine,Thanks.

Code:
SELECT
rtrim(char(substr('123 ABC1',1,LOCATE(' ','123 ABC1'))))
from sysibm.sysdummy1
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 Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
No new posts find RACF group for access to spooled... jzhardy JCL & VSAM 1 Mon May 08, 2017 11:46 am
No new posts To find out size allocated to a seque... ashek15 JCL & VSAM 15 Thu Apr 27, 2017 9:42 am
No new posts Replacing same string with different ... vickey_dw DFSORT/ICETOOL 6 Wed Feb 22, 2017 10:44 pm
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm


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