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
 
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: 1281
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 Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm
No new posts how to see when the last read access ... Mike 1304 DB2 1 Tue Sep 12, 2017 7:52 pm
No new posts Working with hex values in Filemanage... Emile Straker IBM Tools 0 Tue Sep 12, 2017 1:42 am

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