Solved

How to filter a SQL query on  a substring

Posted on 2014-09-29
3
510 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
  • 2
3 Comments
 
LVL 76

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 76

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
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, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

821 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