Solved

Date query not running correctly

Posted on 2007-03-20
3
196 Views
Last Modified: 2010-03-20
Oracle, SQL:
When running this query it is returning all rows,  the column "Initial_scan_date" is a date field.  It is not filtering at all to any dates.  Dates in the column are example:  07/01/2006, 12/21/2006 09:05:26 in both formats.  Any idea's???

select to_date(to_char(INITIAL_SCAN_DATE,'MM/DD/YYYY'), 'MM/DD/YYYY')"Inital_date"
from SEC_ADMIN_JUSTIFICATION
where REC_SOURCE = 'UTS' or REC_SOURCE = 'WIN SERVE'
and to_date(to_char(INITIAL_SCAN_DATE,'MM/DD/YYYY'), 'MM/DD/YYYY') BETWEEN to_date('01/01/2007', 'MM/DD/YYYY')AND sysdate
0
Comment
Question by:knamc
  • 2
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18758639
maybe this works better:

select TRUNC(INITIAL_SCAN_DATE) "Inital_date"
from SEC_ADMIN_JUSTIFICATION
where REC_SOURCE = 'UTS' or REC_SOURCE = 'WIN SERVE'
and TRUNC(INITIAL_SCAN_DATE) >= to_date('01/01/2007', 'MM/DD/YYYY')
AND TRUNC(INITIAL_SCAN_DATE) <= sysdate
0
 

Author Comment

by:knamc
ID: 18758648
Still returning all dates??? Not filtering??
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18758764
I see now, you have an OR without brackets...

select to_date(to_char(INITIAL_SCAN_DATE,'MM/DD/YYYY'), 'MM/DD/YYYY')"Inital_date"
from SEC_ADMIN_JUSTIFICATION
where ( REC_SOURCE = 'UTS' or REC_SOURCE = 'WIN SERVE' )
and to_date(to_char(INITIAL_SCAN_DATE,'MM/DD/YYYY'), 'MM/DD/YYYY') BETWEEN to_date('01/01/2007', 'MM/DD/YYYY')AND sysdate

alternatively:

select to_date(to_char(INITIAL_SCAN_DATE,'MM/DD/YYYY'), 'MM/DD/YYYY')"Inital_date"
from SEC_ADMIN_JUSTIFICATION
where REC_SOURCE IN ( 'UTS'  ,  'WIN SERVE' )
and to_date(to_char(INITIAL_SCAN_DATE,'MM/DD/YYYY'), 'MM/DD/YYYY') BETWEEN to_date('01/01/2007', 'MM/DD/YYYY')AND sysdate
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
awk and Pythagoras? 5 19
subtr returning incorrect value 8 31
date show only hh:mm 2 27
Trouble with <> 2 21
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

831 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