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

SQL CODE -132. Issue with LIKE operator


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

Active User


Joined: 31 Mar 2010
Posts: 134
Location: India

PostPosted: Wed Jan 30, 2013 3:22 pm
Reply with quote

Hi,
I am trying to run the following query in SPUFI.

Code:

    SELECT TAB1.OUT_FLG                                           
      FROM DEVB.TAB2_DEPT     TAB2,                           
           DEVB.TAB1_PROD_TYP TAB1                             
           WHERE TAB2.UNIT_ID = 'ABD'                         
             AND TAB2.DEPT_ID = '01'                             
             AND TAB1.PROD_TYP_DSC LIKE                           
             CHAR('''%'||RTRIM(TAB2.DEPT_DSC)||'%''')       
     FETCH FIRST 1   ROW ONLY                                         
     WITH UR; 


It is giving the SQLCODE=-132 which says that "ERROR: AN OPERAND OF LIKE IS NOT VALID".

I tried to use concat function also instead of using the operator '||'. Does anybody having any idea what is wrong in the query? Any help is highly appreciated. Thanks.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Wed Jan 30, 2013 4:56 pm
Reply with quote

Hi,

Its becuase DB2 will convert the the entire string to CHAR and then it will use for LIKE operation where it will not get the '% ' required for LIKE parameter

regards,
Chandan
Back to top
View user's profile Send private message
GaganGarg

Active User


Joined: 31 Mar 2010
Posts: 134
Location: India

PostPosted: Wed Jan 30, 2013 4:59 pm
Reply with quote

I have given CHAR after LIKE operator because TAB1.PROD_TYP_DSC column is having datatype CHAR. I could not get what you want to say.
I used CHAR('''%'||RTRIM(TAB2.DEPT_DSC)||'%''') in the select clause instead of using it in WHERE clause. There it is getting displayed as '%MEAT%' if the column TAB2.DEPT_DSC is having the value MEAT in the table TAB2. And, '%MEAT%' should be the value which can be used with LIKE operator. but i am getting SQLCODE=-132 when i use it in WHERE clause. .
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Wed Jan 30, 2013 5:42 pm
Reply with quote

Here as you are getting '%MEAT%' as a result of CHAR function DB2 will consider '%MEAT%' as char entire string including '%'.
This % will not be considered as one which DB2 uses for LIKE operation.
Back to top
View user's profile Send private message
GaganGarg

Active User


Joined: 31 Mar 2010
Posts: 134
Location: India

PostPosted: Wed Jan 30, 2013 5:48 pm
Reply with quote

Ohk. Any other way to do the same in query?
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Wed Jan 30, 2013 7:34 pm
Reply with quote

I am not sure but I think you cant use another DB2 column in LIKE parameter..

But let other people go through this post as they will be able to guide you correctly
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Thu Jan 31, 2013 4:51 pm
Reply with quote

You can try locate instead.
locate(TAB2.DEPT_DSC,TAB1.PROD_TYP_DSC) <> 0
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 SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Compile rexx code with jcl CLIST & REXX 6
No new posts REXX code to expand copybook in a cob... CLIST & REXX 2
No new posts Issue after ISPF copy to Linklist Lib... TSO/ISPF 1
Search our Forums:

Back to Top