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
 

 

Query to fetch X'05' values from table

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

New User


Joined: 14 Nov 2007
Posts: 36
Location: Chennai

PostPosted: Tue Sep 08, 2009 10:02 pm    Post subject: Query to fetch X'05' values from table
Reply with quote

Hi,

Our process has inserted invalid values in a table with X'05' in all the columns.The reason for wrong insertion is due to the X'05' were not removed from the input file before running the process.

Please help me out to write a query to fetch the values from table consisting of X'05' value.

The invalid data looks like as shown below:

Code:

Table: DEVD.TABLE1(T1)
EFF_DATE    REC_NUM      FIRST_NAME        LAST_NAME   
----------- ------------------------------------------------------
2007-01-01  2007-01.   .MARIAJON.           .JR.             
2007-01-01  2007-01                                             
2007-01-01  2007-02.   .CHARLE.             .JOSEPH.       
2007-01-01  2007-02    CHARLE               JOSEPH         
2007-01-01  2007-03.   ..                   ..                 
2007-01-01  2007-03                                   


The dots '.' are X'05' values.To fetch this I have written a query as mentioned below, so result set is of valid and invalid rows.

Code:

SELECT * FROM DEVD.TABLE1
WHERE REC_NUM LIKE '2007-0%'


Please help me to write a query to fetch only the X'05' rows.Desired output should be

Code:

Table: DEVD.TABLE1(T1)
EFF_DATE    REC_NUM      FIRST_NAME        LAST_NAME   
----------- ------------------------------------------------------
2007-01-01  2007-01.   .MARIAJON.           .JR.             
2007-01-01  2007-02.   .CHARLE.             .JOSEPH.       
2007-01-01  2007-03.   ..                   ..                 
Back to top
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Sep 09, 2009 1:49 am    Post subject:
Reply with quote

Hello,

Suggest you unload the table, correct the data and reload the data - either for some particular date(s) or for the entire table. . .

If only part of the data was to be corrected (rather than the entire table), those rows would need to be deleted.
Back to top
View user's profile Send private message
lkhiger

New User


Joined: 28 Oct 2005
Posts: 89

PostPosted: Wed Sep 09, 2009 9:23 am    Post subject: Re: Query to fetch X'05' values from table
Reply with quote

Krishnadeva Reddy wrote:
Hi,

Our process has inserted invalid values in a table with X'05' in all the columns.The reason for wrong insertion is due to the X'05' were not removed from the input file before running the process.

Please help me out to write a query to fetch the values from table consisting of X'05' value.

The invalid data looks like as shown below:

Code:

Table: DEVD.TABLE1(T1)
EFF_DATE    REC_NUM      FIRST_NAME        LAST_NAME   
----------- ------------------------------------------------------
2007-01-01  2007-01.   .MARIAJON.           .JR.             
2007-01-01  2007-01                                             
2007-01-01  2007-02.   .CHARLE.             .JOSEPH.       
2007-01-01  2007-02    CHARLE               JOSEPH         
2007-01-01  2007-03.   ..                   ..                 
2007-01-01  2007-03                                   


The dots '.' are X'05' values.To fetch this I have written a query as mentioned below, so result set is of valid and invalid rows.

Code:

SELECT * FROM DEVD.TABLE1
WHERE REC_NUM LIKE '2007-0%'


Please help me to write a query to fetch only the X'05' rows.Desired output should be

Code:

Table: DEVD.TABLE1(T1)
EFF_DATE    REC_NUM      FIRST_NAME        LAST_NAME   
----------- ------------------------------------------------------
2007-01-01  2007-01.   .MARIAJON.           .JR.             
2007-01-01  2007-02.   .CHARLE.             .JOSEPH.       
2007-01-01  2007-03.   ..                   ..                 


You can use something like this:

Code:
SELECT * FROM DEVD.TABLE1
WHERE REC_NUM LIKE '2007-0%'
    and  possn(REC_NUM || first_name || last_name , X'05') > 0 


Lenny
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1280
Location: Belgium

PostPosted: Wed Sep 09, 2009 11:58 am    Post subject:
Reply with quote

or you could just
Code:
update devd.tabl1
set last_name = replace(last_name,x'05','')
    ,first_name = replace(first_name,x'05','')

where (last_name like '%'!!x'05'!!'%' or first_name like '%'!!x'05'!!'%')
and REC_NUM LIKE '2007-0%'
Back to top
View user's profile Send private message
Krishnadeva Reddy

New User


Joined: 14 Nov 2007
Posts: 36
Location: Chennai

PostPosted: Wed Sep 09, 2009 10:03 pm    Post subject: Reply to: Query to fetch X'05' values from table
Reply with quote

Thanks for your help.

With POSSTR function I was able to get desired results from the below query.

Code:

SELECT * FROM DEVD.TABLE1
WHERE REC_NUM LIKE '2007-0%'
    AND POSSTR(ID_REC || NME_FRST_PROV || NME_LAST_PROV, X'05') > 0 
Back to top
View user's profile Send private message
lkhiger

New User


Joined: 28 Oct 2005
Posts: 89

PostPosted: Thu Sep 10, 2009 6:46 am    Post subject: Correction
Reply with quote

Code:
SELECT * FROM DEVD.TABLE1
WHERE REC_NUM LIKE '2007-0%'
    and  POSSTR(REC_NUM || first_name || last_name , X'05') > 0


But finally you can update without select

Code:
Update DEVD.TABLE1
set
REC_NUM  = replace(REC_NUM, X'05', ' '),
first_name = replace(first_name, X'05', ' '),
last_name = replace(last_name, X'05', ' ')
WHERE REC_NUM LIKE '2007-0%'
    and  POSSTR(REC_NUM || first_name || last_name , X'05') > 0


I see you found and corrected my mistake. icon_exclaim.gif icon_exclaim.gif icon_exclaim.gif

Thanks, Lenny icon_rolleyes.gif icon_rolleyes.gif icon_rolleyes.gif
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 Check Binary Values for symbols gandikk CA Products 3 Tue Mar 21, 2017 5:11 am
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts To display values of multiple rows in... vinu78 DB2 2 Thu Mar 09, 2017 1:20 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts Replacing same string with different ... vickey_dw DFSORT/ICETOOL 6 Wed Feb 22, 2017 10:44 pm


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