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 > LIKE operator with CONCAT

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-25-05, 13:16
carlosgg carlosgg is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
LIKE operator with CONCAT

DB2 version 8.1.3.132 in Win XP.

I'm trying to use the LIKE operator and the CONCAT operator in the same sentence. Although it works fine when concatenating two strings, it fails when concatenating a VARCHAR column and a string.

Something like this:
Code:
SELECT 
  MOVIE.TITLE
FROM
  MOVIE
WHERE
  MOVIE.TITLE LIKE MOVIE.TITLE2 || 'My beautyful string'
I get the DBA2191E error

Have any idea?

Thank you in advance.

..:: Carlos ::..
Reply With Quote
  #2 (permalink)  
Old 02-25-05, 13:31
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
see if the content of this thread is of any help

http://www.dbforums.com/t1118136.html
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 02-25-05, 13:39
achiola achiola is offline
Registered User
 
Join Date: May 2002
Location: General Deheza, Cba, Arg.
Posts: 273
well, test this:

with temp1 as (
SELECT
MOVIE.ID,
MOVIE.TITLE LIKE MOVIE.TITLE2 || 'My beautyful string' newField
FROM
MOVIE
)
SELECT
MOVIE.TITLE
FROM
MOVIE
on temp.id = movie.id
WHERE
MOVIE.TITLE LIKE temp1.newField
Reply With Quote
  #4 (permalink)  
Old 02-26-05, 01:37
jacampbell jacampbell is offline
Registered User
 
Join Date: Jan 2005
Posts: 191
LIKE operators normally use underscores and percent signs on the right hand side. I'm not sure where these are in your query. However you might be looking for something like
where posstr(MOVIE.TITLE, MOVIE.TITLE2 || 'My beautyful string') > 0

James Campbell
Reply With Quote
  #5 (permalink)  
Old 03-01-05, 11:59
carlosgg carlosgg is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
Thank you all,

It seems that I cannot make working the solution provided by jacampbell, and the one by achiola is too complicated.

The problem with this kind of queries is that they are dynamically generated, according to some users entry.

What I think I will do is to solve this part of the querie in Java, by using the "startsWith" method.

..:: Carlos ::..
Reply With Quote
  #6 (permalink)  
Old 03-01-05, 13:15
juan_carlos juan_carlos is offline
Registered User
 
Join Date: Feb 2005
Location: Puerto Rico
Posts: 16
Cool to char and %

try this in the statement you have

...char(MOVIE.TITLE2) || char('My beautyful string')

if you are using the LIKE operand you should also include the %.

...char(MOVIE.TITLE2) || char('My beautyful string%')

Try and let me know...

J.C.
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