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

Problem with condition checking in a VARCHAR DB2 field


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

New User


Joined: 03 Sep 2009
Posts: 18
Location: chennai

PostPosted: Mon Dec 12, 2011 2:20 pm
Reply with quote

Hi,

I have a varchar(100) field say Field5 in a DB2 table which is loaded by a third party. In my SP am using this field in the inner query

Code:

EXEC SQL                                                 
   SELECT                                                 
      C.Field1 ,C.Field2                                   
   INTO                                                   
      :WS-A ,:WS-B                   
   FROM                                                   
      TABLE1  A, TABLE2  B, TABLE3  C                                 
   WHERE                     
       A.Field1   = C.Field1 AND                                       
       A.Field3   = B.Field3 AND                                 
       C.Field1 IN                   
      (SELECT Field1 FROM TABLE3
       WHERE  Field4     = 1290             
       AND    Field5    ¬= '0001')
END-EXEC     

If Field5 is having value 0001 then Field5 len --> 4 and Field5 Text--> 0001 (remaining 96 bytes are spaces)
Scenario 1
In other cases Field5 had Field5 len --> 4 and Field5 Text --> low-values for all 100 bytes
Scenario 2
There was a new data update by the third party recently after which Field5 had the following values other than 0001 Field5 len --> 0 and Field5 Text --> Null

For Scenario 1 the above query worked whereas after data update for Scenario 2 the query did'nt work, and we had to revert back the changes.
Since we are getting the data from 3rd party we are trying to fix it from our side if possible before going back to them. We thought of doing a 1 time update however the third party does a weekly refresh, so the 1 time changes we make may not last

1. Is there any way to check for Field5 ¬= '0001' if the DB has NULL values in SP
2. Is it mandatory for the Field5 len to be 4 since we are checking 4 byte value '0001' in the query

Please help
Back to top
View user's profile Send private message
Nandhu86

New User


Joined: 03 Jun 2009
Posts: 1
Location: Chennai

PostPosted: Mon Dec 12, 2011 4:45 pm
Reply with quote

Try this query for checking NULL values

Code:

EXEC SQL                                                 
   SELECT                                                 
      C.Field1 ,C.Field2                                   
   INTO                                                   
      :WS-A ,:WS-B                   
   FROM                                                   
      TABLE1  A, TABLE2  B, TABLE3  C                                 
   WHERE                     
       A.Field1   = C.Field1 AND                                       
       A.Field3   = B.Field3 AND                                 
       C.Field1 IN                   
      (SELECT Field1 FROM TABLE3
      AND (Field5    ¬= '0001' OR
   FIELD5 IS NULL))
END-EXEC 
Back to top
View user's profile Send private message
jothibso

New User


Joined: 03 Sep 2009
Posts: 18
Location: chennai

PostPosted: Mon Dec 12, 2011 5:25 pm
Reply with quote

Thanks Nandhu it worked
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 Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts S0C7 - Field getting overlayed COBOL Programming 2
Search our Forums:

Back to Top