-2

Hi i'm having trouble with my query i'm suppose to get values by two datetime conditions as so:

 select * 
from cns_concerto_projects 
where SST_CREATION_DATE> TO_DATE('02/27/2010 16:07:07', 'mm/dd/yyyy HH24:MM:SS') 
AND SST_MODIFIED_DATE > TO_DATE('03/26/2010 11:42:07', 'mm/dd/yyyy  HH24:MM:SS') < sysdate

could you please assist to correct this issue.

Thank a lot.

0

3 Answers 3

1

The problem is your last line in the where.

You need to use between if you want to search a range.

So instead of this:

SST_MODIFIED_DATE > TO_DATE('03/26/2010 11:42:07', 'mm/dd/yyyy HH24:MM:SS') < sysdate

Use this:

select *
from   cns_concerto_projects
where  SST_CREATION_DATE > TO_DATE('02/27/2010 16:07:07', 'mm/dd/yyyy HH24:MI:SS')
AND    SST_MODIFIED_DATE between TO_DATE('03/26/2010 11:42:07', 'mm/dd/yyyy HH24:MI:SS') and sysdate

Also, you have to use mi for minutes, instead of mm.

If you want to remove the between use this:

select *
from   cns_concerto_projects
where  SST_CREATION_DATE >  TO_DATE('02/27/2010 16:07:07', 'mm/dd/yyyy HH24:MI:SS')
AND    SST_MODIFIED_DATE >= TO_DATE('03/26/2010 11:42:07', 'mm/dd/yyyy HH24:MI:SS')
AND    SST_MODIFIED_DATE <=  sysdate
6
  • Still incorrect. Have a look at the second parameter of to_date functions
    – cha
    May 1, 2014 at 12:51
  • Using between on date time fields is often a bad idea. Minus 1.
    – Dan Bracuk
    May 1, 2014 at 12:54
  • Bad idea because of the confusion it brings into understanding what is included. You really do not know without consulting the manual if it is a <= b <= c or a < b < c or a <= b < c or a < b <= c
    – cha
    May 1, 2014 at 12:59
  • I misread the question. The keyword between does not seem to be applicable anywhere in this case. In other cases, going for where something between DateA and DateB could cause you to miss records that happened on DateB, if the values include the time of day.
    – Dan Bracuk
    May 1, 2014 at 13:00
  • @DanBracuk: still don't entirely understand you. I got the point of the confusion, but why is between not applicable? The last where clause compares one date to two values. May 1, 2014 at 13:04
0

you can use it in following way:

select * from cns_concerto_projects 
where SST_CREATION_DATE > TO_DATE('02/27/2010 16:07:07', 'mm/dd/yyyy HH24:MM:SS') 
AND 
(SST_MODIFIED_DATE > TO_DATE('03/26/2010 11:42:07', 'mm/dd/yyyy HH24:MM:SS') And SST_MODIFIED_DATE < sysdate)
0
0

If it is guaranteed that SST_MODIFIED_DATE will be greater than SST_CREATION_DATE always, then you can skip the first condition, as follows:

select * 
from cns_concerto_projects 
where SST_MODIFIED_DATE BETWEEN TO_DATE('03/26/2010 11:42:07', 'mm/dd/yyyy HH24:MI:SS') AND sysdate;

Here's the version without using BETWEEN:

select * 
from cns_concerto_projects 
where SST_MODIFIED_DATE >= TO_DATE('03/26/2010 11:42:07', 'mm/dd/yyyy HH24:MI:SS') 
AND SST_MODIFIED_DATE <= sysdate;
2
  • Maybe I'll correct the myself The dates I wrote was not intended to be a range but a two condition query for dates
    – Yotam707
    May 1, 2014 at 16:04
  • @Yotam707 What are your two datetime conditions?
    – Joseph B
    May 1, 2014 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.