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 > Parameter in a Like Predicate

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-19-10, 21:53
ProXtremer ProXtremer is offline
Registered User
 
Join Date: May 2010
Posts: 3
Parameter in a Like Predicate

Hello everybody,

I want to ask you for help. I'm trying to create a procedure with a input parameter for instance "var1". And in the procedure I'm using LIKE predicate, where I want to put the parameter in the pattern side.
Something like this:

..... WHERE r.name LIKE '%var1%' .........

but it takes var1 like a char, not like a parameter, so if you have some advices I'll be glad

Thank you all.
Reply With Quote
  #2 (permalink)  
Old 05-20-10, 03:09
dbzTHEdinosaur dbzTHEdinosaur is offline
Registered User
 
Join Date: Jun 2007
Location: germany
Posts: 96
never concatonated a like predict
LIKE '%'||var1||'%'

but most times, I build the % within var1
__________________
Dick Brenholtz, Ami in Deutschland

Last edited by dbzTHEdinosaur; 05-20-10 at 03:15.
Reply With Quote
  #3 (permalink)  
Old 05-23-10, 09:37
DB2Plus DB2Plus is offline
Registered User
 
Join Date: Jul 2009
Posts: 150
Arrow Like ==> locate

Quote:
Originally Posted by dbzTHEdinosaur View Post
never concatonated a like predict
LIKE '%'||var1||'%'

but most times, I build the % within var1
Instead of LIKE you can use LOCATE function. With the same result.

Kara
Reply With Quote
  #4 (permalink)  
Old 05-29-10, 08:51
ProXtremer ProXtremer is offline
Registered User
 
Join Date: May 2010
Posts: 3
Index Structure. Has table

Thank you all
Reply With Quote
  #5 (permalink)  
Old 05-29-10, 11:35
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by ProXtremer View Post
Hello everybody,

I want to ask you for help. I'm trying to create a procedure with a input parameter for instance "var1". And in the procedure I'm using LIKE predicate, where I want to put the parameter in the pattern side.
Something like this:

..... WHERE r.name LIKE '%var1%' .........

but it takes var1 like a char, not like a parameter, so if you have some advices I'll be glad

Thank you all.
You can use dynamic SQL to create the SQL statement, the prepare and execute it (or execute immediate).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
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