Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Date query not running correctly

Posted on 2007-03-20
3
Medium Priority
?
206 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 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

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.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

618 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