[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Help on an Oracle Query

Posted on 2010-11-16
6
Medium Priority
?
319 Views
Last Modified: 2012-06-21
For anyone who knows Oracle this should be cake.  For me being proficient and used to SQL Server this is a complete headache that I can't figure out something that would be so easy.

I've got a table called Customer with a relevant column ExpirationDate

I need a query that will return all the records in this table where the expirationDate is less than the current date.  Or in other words, all records having an expiration data that has already passed.

This is what I have so far...
SELECT * FROM Customer
WHERE EXPIRATIONDATE < SYSDATE

which sort of works, but I need records that have an expiration date of the current date not to show up in the query.

The expiration dates in the table are all in the form of...
16-NOV-10 12.00.00

So because SYSDATE returns a date that has a time that is later in the day than the DateTime above, that record is being included in the query.  I only want a record having an expiration date of 16-Nov to show up in this query if today's date were 17-Nov or later.

Thanks for the help.
0
Comment
Question by:JosephEricDavis
6 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 1800 total points
ID: 34150145
try this.


SELECT * FROM Customer
WHERE EXPIRATIONDATE < TRUNC(TO_DATE(SYSDATE),'DD')
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34150146
Use TRUNC(SYSDATE)
0
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 200 total points
ID: 34150167
Just noticed the other comment

SYSDATE is already a date, so TO_DATE is superfluous.  Also, the default for TRUNC is to a whole number, which is the day, so 'DD' is not required, so

< TRUNC(SYSDATE)

is all that is required (but the first comment is not wrong)
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 3

Expert Comment

by:paulwquinn
ID: 34150219
Use the TRUNC function on SYSDATE to effectively set the time to 0000 hours, i.e. midnight. The inequality comparison in the WHERE clause will then only pick up dates prior to SYSDATE.

SELECT * FROM Customer
WHERE EXPIRATIONDATE < SELECT TRUNC(SYSDATE) FROM DUAL;
0
 
LVL 1

Expert Comment

by:sunny25
ID: 34152907
this query should give you the desired result
:-SELECT * FROM Customer
WHERE trunc(EXPIRATIONDATE) < trunc(SYSDATE)
Trunc() function truncates the time part from date and return only the date
0
 
LVL 7

Author Closing Comment

by:JosephEricDavis
ID: 34155855
I'm in the habit of giving points to the first guy that has a working post and not splitting them with folks that chime in after with the same answer.  But this one was a hard call as the first answer did work but the second answer was an improvement upon.  Therefore I chose to award points as I have.

Thanks guys.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

829 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