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 > Using 'Select.. Where... LIKE'

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-07-10, 10:54
itsonlyme44 itsonlyme44 is offline
Registered User
 
Join Date: Dec 2007
Posts: 261
Using 'Select.. Where... LIKE'

Running DB2 on Windows V 9.5

using this SQL
Select * from schema.table where columnname like '%2010-10-01%'

Getting this error
42884(-440)[IBM][CLI Driver][DB2/NT] SQL0440N No authorized routine named "LIKE" of type "FUNCTION" having compatible arguments was found. SQLSTATE=42884
(0.20 secs)

Is my Syntax wrong???
Reply With Quote
  #2 (permalink)  
Old 10-07-10, 11:35
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
If columnname has type DATE or TIMESTAMP you can't use LIKE.

You have to use LIKE only for type CHAR and VARCHAR.

For type DATE or TIMESTAMP operation could be =, >=, <=, >, <, BETWEEN.

Lenny
Reply With Quote
  #3 (permalink)  
Old 10-07-10, 11:48
itsonlyme44 itsonlyme44 is offline
Registered User
 
Join Date: Dec 2007
Posts: 261
Thank you!!!! Between will work !
Reply With Quote
  #4 (permalink)  
Old 10-07-10, 12:02
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Lightbulb CHAR(columnname) like

You can also use for any types:

Code:
Select * from schema.table 
where CHAR(columnname) like '%2010-10-01%'
But it could also badly affect performance of the query.

Lenny
Reply With Quote
  #5 (permalink)  
Old 10-07-10, 12:13
itsonlyme44 itsonlyme44 is offline
Registered User
 
Join Date: Dec 2007
Posts: 261
Awesome! That worked beautifully!
Reply With Quote
  #6 (permalink)  
Old 10-07-10, 12:54
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Arrow Next step to understanding

Also, you don't need to use first "%" in the statement:

Code:
Select * from schema.table 
where CHAR(columnname) like '2010-10-01%'
Lenny
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