Solved

How to filter a SQL query on  a substring

Posted on 2014-09-29
3
543 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to recover a database from a user managed backup
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

733 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