conditional date range using CASE statement in WHERE clause [message #501326] |
Mon, 28 March 2011 09:41  |
staann56
Messages: 136 Registered: May 2006 Location: atlanta
|
Senior Member |
|
|
Is it possible within a CASE statement to put conditions on the date range that I want to pull? IE: am versus pm. The query has to pull specific time ranges for an AM run versus a PM run.
.....
FROM
table
WHERE
CASE
WHEN TO_CHAR(SYSDATE,'AM') = 'AM'
THEN table.date BETWEEN TRUNC(SYSDATE) AND SYSDATE
ELSE table.date BETWEEN TRUNC(SYSDATE+12/24) AND SYSDATE
any suggestions would be greatly appreciated.
Stan
[Updated on: Mon, 28 March 2011 10:25] by Moderator Report message to a moderator
|
|
|
|
|
Re: conditional date range using CASE statement in WHERE clause [message #501341 is a reply to message #501330] |
Mon, 28 March 2011 11:28   |
staann56
Messages: 136 Registered: May 2006 Location: atlanta
|
Senior Member |
|
|
thank you very much for the replies. Unfortunately, neither of these will work. I'm probably not explaining clearly what I'm trying to do. Currently I have an AM and a PM version of a query that I need to consolidate into one query.
The AM version uses these times for data capture:
....
FROM
table
WHERE
table.date > (TRUNC(SYSDATE-1)+(19*60+0)/1440)
and the PM version uses these times for data capture:
>
....
FROM
table
WHERE
table.date > (TRUNC(SYSDATE)+(7*60+0)/1440)
If possible I need the query when ran in the AM or PM to use the correct time constraint respectively.
So to summarize, if the query is ran during any AM hour it pulls based on the first date constraint listed above else the second date constraint.
Thanks - Stan.
|
|
|
|
|
|