If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Usage of LIKE with content from another cell

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-07-09, 04:58
Flamacue Flamacue is offline
Registered User
 
Join Date: Sep 2009
Location: Munich, Germany
Posts: 3
Usage of LIKE with content from another cell

DB2-Version: v8.1 on z/os

Hi everyone,

I am trying to use the LIKE operator in the following way:

Code:
  SELECT                                                             
      *                             
  FROM                                                               
      GG$TUK6.TVERMITTLER_DEF a,                                     
      GG$TUK6.TDE1ASAB02AREGART b                                     
  WHERE                                                              
      a.ADCODE_ALT = '73320940'                                    
      and b.DE1_VERMFUNK_LIST LIKE concat(a.vermfunk,'%')
I receive the following error:
SQL0132N
A LIKE predicate or POSSTR scalar function is not valid because the first operand is not a string expression or the second operand is not a string.


Both operands are strings, so I don't see where the problem is.

Any ideas? Is this possible with DB2 at all?

Thanks,
Christian
Reply With Quote
  #2 (permalink)  
Old 09-07-09, 05:35
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
it should be
col LIKE a.vermfunk concat '%' instead of
LIKE concat(a.vermfunk,'%')
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #3 (permalink)  
Old 09-07-09, 05:53
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
Is not allowed in DB2 LUW .. Zos i cant say..
I faced many such codes while converting Sybase to DB2

Play with locate function
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #4 (permalink)  
Old 09-07-09, 06:01
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
DB2 requires a constant expression. Using the value from another column is not constant. Depending on what you want to achieve, consider the LOCATE() or POSSTR() functions.

Here is the manual where this is explicitly stated: http://publib.boulder.ibm.com/infoce...epredicate.htm
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 09-07-09, 07:25
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
This is one of the restriction of DB2.
A column name(and an expression(concatenation, etc.) including column name) can't be used for the pattern-expression of LIKE predicate.

Even newest DB2 version(DB2 9.7 for LUW) still has this restriction.

I discussed this issue in the following thread.
Compatibility of LIKE predicate on DB2 V9.7 with Oracle.:
comp.databases.ibm-db2 | Google Groups

For your case:
"and b.DE1_VERMFUNK_LIST LIKE concat(a.vermfunk,'%')"
will be replaced by:
"and LOCATE(a.vermfunk, b.DE1_VERMFUNK_LIST) = 1"
as Rahul Singh wrote.
Reply With Quote
  #6 (permalink)  
Old 09-07-09, 09:08
Flamacue Flamacue is offline
Registered User
 
Join Date: Sep 2009
Location: Munich, Germany
Posts: 3
I changed the line to:
and LOCATE(a.vermfunk, b.DE1_VERMFUNK_LIST) <> 0

This seems to be doing what I want.

Thanks everyone,
Christian
Reply With Quote
  #7 (permalink)  
Old 09-07-09, 09:32
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
<>0
i guess it will behave %abc% instead of abc%
=1 will be gud
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #8 (permalink)  
Old 09-07-09, 10:00
Flamacue Flamacue is offline
Registered User
 
Join Date: Sep 2009
Location: Munich, Germany
Posts: 3
Good point, Rahul! But indeed, %abc% was what I really needed. My original example just didn't reflect that. Sorry for the confusion.

Thanks,
Christian
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On