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

Query to fetch X'05' values from table


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

New User


Joined: 14 Nov 2007
Posts: 37
Location: Chennai

PostPosted: Tue Sep 08, 2009 10:02 pm
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

Moderator Emeritus


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

PostPosted: Wed Sep 09, 2009 1:49 am
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
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
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: 37
Location: Chennai

PostPosted: Wed Sep 09, 2009 10:03 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts RC query -Time column CA Products 3
Search our Forums:

Back to Top