Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • Last Modified:

How to filter a SQL query on a substring

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
mariita
Asked:
mariita
  • 2
1 Solution
 
slightwv (䄆 Netminder) Commented:
>> 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
 
slightwv (䄆 Netminder) Commented:
or
and substr(COURSE_START_DATE,-2,2) in ('09','10','11','12')
0
 
mariitaAuthor Commented:
Last two. Thanks!
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now