SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How do I search by DATE then TIME in Oracle?


How do I search by DATE then TIME in Oracle?

Author
Message
jess.
jess.
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 41
I have a query that pulls back both a Time and a Date column. I'm trying to figure out how I can search by the date and then by the time.
Currently, I have a statement to search by the date but when I add a time statement, no results are pulled back and I know they should be there.

Idealy, an example i'd like to see are all results on the 18th from 05:00 until 17:00 that day.

Any ideas?

Thanks,
jess.

This is a sample result set:

TIME_C LANE ITEMS DATE_C BU CUST BAL
05:00:00 1 1 11/18/2012 1234 1 1.59
10:00:00 1 2 11/18/2012 1234 1 1.09
22:00:00 1 3 11/18/2012 1234 1 1.42

This is my code:

SELECT
TO_CHAR(TO_DATE(CASE WHEN TO_NUMBER(TO_CHAR(TIME_C, 'mi')) > 59 THEN TO_CHAR(TRUNC(TIME_C, 'hh') + 1 / 48, 'hh24:mi:ss')ELSE TO_CHAR(TRUNC(TIME_C, 'hh'), 'hh24:mi:ss') END,'hh24:mi:ss'),'hh24:mi:ss') AS TIME_C,
LANE,
DTL_TY AS ITEMS,
DATE_C,
BU,
COUNT(DATE_C) AS CUST,
SUM(BAL_AMT) AS BAL
FROM
(
SELECT
DTL_QTY,
DATE_C,
BU,
BAL_AMT,
LANE,
TIME_C
FROM TRANS_C
WHERE
BU IN (329)
AND LANE < 30
AND DATE_C BETWEEN TO_DATE ('11/18/2012','mm/dd/yyyy') AND TO_DATE ('11/24/2012','mm/dd/yyyy')
)
GROUP BY
TIME_C,
LANE,
DTL_TY,
DATE_C,
BU
ORDER BY BU, DATE_C, LANE

PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
SSCertifiable
SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)

Group: General Forum Members
Points: 5531 Visits: 4639
Could you please post the schema of the table? I'm curious about the datatype of date_c and time_c columns.

_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search