Solved

Help on an Oracle Query

Posted on 2010-11-16
6
310 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 40

Accepted Solution

by:
Sharath earned 450 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 50 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DBF to ... Converter 5 69
Sql Join Problem 2 43
SSRS troubles 4 47
run sql script from putty 4 35
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
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 shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

785 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