Solved

Date query not running correctly

Posted on 2007-03-20
3
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

707 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