August 18, 2010 at 5:33 pm
I have a query that display a result beetween dates (mm/dd/yyyy hh24:mi:ss) but i need to separate those results hourly, here is the query:
select pass_fail_indicator
from unit_status
where station = 'LG01-TIDASSGN-03'
and pass_fail_indicator = 'P'
and modified_date
between to_date('08/18/2010 08:00:00','mm/dd/yyyy hh24:mi:ss')
and to_date('08/18/2010 15:00:00','mm/dd/yyyy hh24:mi:ss');
and i get the result beetwen those dates, but i need to separate the result of this query by hour,
for example if i choose start date '08/18/2010 00:00:00' and end date '08/18/2010 03:00:00' i need the result from '08/18/2010 00:00:00' to '08/18/2010 01:00:00' and from '08/18/2010 01:00:00' to '08/18/2010 02:00:00' etc...
it can be possible????
any help you can provide me I'll be very thankful
August 19, 2010 at 11:30 am
So you would want 08/19/2010 13:15 to show up as 08/19/2010 13:00 ?
August 19, 2010 at 11:58 am
Try this:
select pass_fail_indicator, CONVERT(nvarchar(10), modified_date, 101), DATEPART(hour, modified_date)
from unit_status
where station = 'LG01-TIDASSGN-03'
and pass_fail_indicator = 'P'
and modified_date
between to_date('08/18/2010 08:00:00','mm/dd/yyyy hh24:mi:ss')
and to_date('08/18/2010 15:00:00','mm/dd/yyyy hh24:mi:ss')
ORDER BY modified_date, DATEPART(hour, modified_date);
Without your schema and some test data, I can't test this. But it should give you a starting point.
August 19, 2010 at 3:34 pm
select pass_fail_indicator
from unit_status
where station = 'LG01-TIDASSGN-03'
and pass_fail_indicator = 'P'
and modified_date
between to_date('08/18/2010 08:00:00','mm/dd/yyyy hh24:mi:ss')
and to_date('08/18/2010 15:00:00','mm/dd/yyyy hh24:mi:ss');
TO_DATE is an ORACLE function. Use a Tally table for this instead.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 19, 2010 at 3:36 pm
Thanks! Didn't even notice that. Was simply taking what he had and adding the ideas to it.
August 19, 2010 at 3:37 pm
jerry-621596 (8/19/2010)
Thanks! Didn't even notice that. Was simply taking what he had and adding the ideas to it.
Sorry Jerry... didn't mean to direct that at you. Op had it in his original code. I changed my post.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 19, 2010 at 3:38 pm
I'd post a coded answer except I can't start a new message with code in it. The filters at work pick it up as a possible SQL injection attack and prevent the post.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 19, 2010 at 3:41 pm
Info on the Tally table may be found at the following URL. http://www.sqlservercentral.com/articles/T-SQL/62867/
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply