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
 
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: 1910
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: 1910
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: 1910
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 RACF- How to find the Last access of ... rahul shanmuganatan All Other Mainframe Topics 7 Thu Jun 21, 2018 3:19 pm
No new posts IBM website search issues starting 06... harisukumaran General Talk & Fun Stuff 2 Thu Jun 14, 2018 7:48 pm
This topic is locked: you cannot edit posts or make replies. Rexx code to find greater then symobl... Bharath Vikraman CLIST & REXX 8 Tue May 29, 2018 9:40 am
No new posts Find & Replace string in CA-SORT mrgnndhmk CA Products 1 Fri Mar 30, 2018 12:58 am
No new posts Find a string in PS file opened in br... mukkas CLIST & REXX 3 Sat Feb 24, 2018 2:15 pm

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