Solved

How to filter a SQL query on  a substring

Posted on 2014-09-29
3
577 Views
Last Modified: 2014-09-29
I currently have the following inelegant filter hard-coded into my query. Rather than hard-coding dates into the query, I'd like to filter based on a substring, i.e. if the last four characters are 09 or 10 or 11 or 12. How can I do this?

and COURSE_START_DATE in ('201209','201210','201211','201212','201309','201310','201311','201312','201409','201410','201411','201412')

Open in new window

0
Comment
Question by:mariita
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40350162
>> if the last four characters are 09
Last four or last two?

Try this:
and regexp_like(COURSE_START_DATE,'(09|10|11|12)$')
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40350167
or
and substr(COURSE_START_DATE,-2,2) in ('09','10','11','12')
0
 

Author Closing Comment

by:mariita
ID: 40350180
Last two. Thanks!
0

Featured Post

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question