Collapsing rows - date/time ranges

Hi,
I need to collapse date/time ranges (1 range per row) into the smallest continuous block for a particular item, instance (date/time).
For example,
CREATE TABLE "BLOCK_TEST"
   "ID" NUMBER,
   "START_BLK" DATE,
   "STOP_BLK" DATE
alter session set nls_date_format = "YYYY-MM-DD HH24:MI";
INSERT INTO BLOCK_TEST ("ID","START_BLK","STOP_BLK") VALUES (1, TO_DATE('2006-07-03 01:00'), TO_DATE('2006-07-03 01:30'));
INSERT INTO BLOCK_TEST ("ID","START_BLK","STOP_BLK") VALUES (1, TO_DATE('2006-07-03 01:30'), TO_DATE('2006-07-03 02:00'));
INSERT INTO BLOCK_TEST ("ID","START_BLK","STOP_BLK") VALUES (1, TO_DATE('2006-07-03 02:00'), TO_DATE('2006-07-03 02:30'));
INSERT INTO BLOCK_TEST ("ID","START_BLK","STOP_BLK") VALUES (1, TO_DATE('2006-07-03 02:30'), TO_DATE('2006-07-03 03:00'));
INSERT INTO BLOCK_TEST ("ID","START_BLK","STOP_BLK") VALUES (1, TO_DATE('2006-07-03 03:30'), TO_DATE('2006-07-03 04:00'));
INSERT INTO BLOCK_TEST ("ID","START_BLK","STOP_BLK") VALUES (1, TO_DATE('2006-07-03 04:00'), TO_DATE('2006-07-03 04:30'));
INSERT INTO BLOCK_TEST ("ID","START_BLK","STOP_BLK") VALUES (2, TO_DATE('2006-07-03 02:00'), TO_DATE('2006-07-03 02:30'));
INSERT INTO BLOCK_TEST ("ID","START_BLK","STOP_BLK") VALUES (2, TO_DATE('2006-07-03 02:30'), TO_DATE('2006-07-03 03:00'));
INSERT INTO BLOCK_TEST ("ID","START_BLK","STOP_BLK") VALUES (2, TO_DATE('2006-07-03 03:00'), TO_DATE('2006-07-03 03:30'));
select * from block_test order by id, start_blk;
ID      START_BLK               STOP_BLK
1     2006-07-03 01:00     2006-07-03 01:30
1     2006-07-03 01:30     2006-07-03 02:00
1     2006-07-03 02:00     2006-07-03 02:30
1     2006-07-03 02:30     2006-07-03 03:00
1     2006-07-03 03:30     2006-07-03 04:00
1     2006-07-03 04:00     2006-07-03 04:30
2     2006-07-03 02:00     2006-07-03 02:30
2     2006-07-03 02:30     2006-07-03 03:00
2     2006-07-03 03:00     2006-07-03 03:30If ID = 1 and my instance is 2006-07-03 01:45, I need to obtain 2006-07-03 01:00 as the start of the block and 2006-07-03 03:00 as the end - notice the gap from 3:00 to 3:30 so the end would not be 4:30.
I can do this in a procedure but I was wondering if this could be done with just SQL?
Any hints, suggestions or opinions would be welcome.
Thanks,
dfg
EDIT: After re-reading this, need to clarify that I don't need to actually change or update the rows, just query to get the start and end of the block in question...
Message was edited by:
Indy

There might be better ways but the following worked for me
SQL> select
  2        first_value(start_blk) over (partition by id ORDER BY lvl desc),
  3        first_value(stop_blk) over (partition by id ORDER BY lvl desc)
  4  from (select level lvl, id, connect_by_root start_blk start_blk, stop_blk
  5        from (select id , start_blk, stop_blk
  6              from   block_test
  7              where  id=1
  8             )
  9        connect by prior stop_blk=start_blk
10        order by level desc
11       )
12  where to_date('2006-07-03 01:45', 'YYYY-MM-DD HH24:MI') between start_blk and stop_blk
13  and rownum < 2
14  ;
FIRST_VALUE(STAR FIRST_VALUE(STOP
2006-07-03 01:00 2006-07-03 03:00
SQL> select
  2        first_value(start_blk) over (partition by id ORDER BY lvl desc),
  3        first_value(stop_blk) over (partition by id ORDER BY lvl desc)
  4  from (select level lvl, id, connect_by_root start_blk start_blk, stop_blk
  5        from (select id , start_blk, stop_blk
  6              from   block_test
  7              where  id=1
  8             )
  9        connect by prior stop_blk=start_blk
10        order by level desc
11       )
12  where to_date('2006-07-03 03:15', 'YYYY-MM-DD HH24:MI') between start_blk and stop_blk
13  and rownum < 2
14  ;
no rows selected
SQL> select
  2        first_value(start_blk) over (partition by id ORDER BY lvl desc),
  3        first_value(stop_blk) over (partition by id ORDER BY lvl desc)
  4  from (select level lvl, id, connect_by_root start_blk start_blk, stop_blk
  5        from (select id , start_blk, stop_blk
  6              from   block_test
  7              where  id=1
  8             )
  9        connect by prior stop_blk=start_blk
10        order by level desc
11       )
12  where to_date('2006-07-03 03:45', 'YYYY-MM-DD HH24:MI') between start_blk and stop_blk
13  and rownum < 2
14  ;
FIRST_VALUE(STAR FIRST_VALUE(STOP
2006-07-03 03:30 2006-07-03 04:30
SQL>

Similar Messages

  • How to return a specific date/time range and last event details, when checking the event log via command prompt

    I am new to scripting (literally started reading/learning scripting a few hours ago), and I am stuck in trying to get my current script/command to filter a specific date range.
    * Note: I am working with Server 2003 and 2008; because of the environment I am in, a lot of scripts (such as Powershell and VBScript) don't work; trying to stick with command line, as it appears to be the only thing that functions correctly in my environment
    I am trying to search the System log in event viewer, for the most recent server reboot. Here is the command that I am currently running:
    ===========================================================
    C:\Windows\System32\cscript C:\Windows\System32\eventquery.vbs /L System /FI "id eq 1074"
    ===========================================================
    When run, the output looks like this:
    ===========================================================
    Microsoft (R) Windows Script Host Version 5.6
    Copyright (C) Microsoft Corporation 1996-2001. All rights reserved
    Listing the events in 'system' log of host 'xxxxxxxxxxxxxxx'
    Type Event
    Date Time    Source
    Information 1074
    12/18/2013 2:48:06 AM    USER32
    Information 1074
    11/20/2013 3:25:04 AM    USER32
    Information 1074
    10/23/2013 2:06:09 AM    USER32
    ===========================================================
    What I would like it to do is only show events that have happened in the last seven days, as well as show the event details if it does find an event that matches the criteria.
    Any help would be greatly appreciated. Thanks!
    Nick

    I would prefer using Powershell , you can use below code 
    function Get-EventViewer
    param(
    [string[]]$ComputerName = $ENV:COMPUTERNAME,[string]$LogName,[int]$eventid
    $Object =@()
    foreach ($Computer in $ComputerName)
    $ApplicationEvents = get-eventlog -logname $LogName -cn $computer -after (Get-Date).AddDays(-7) | ?{$_.eventid -eq "$eventid" }
    foreach ($event in $ApplicationEvents) {
    $Object += New-Object -Type PSObject -Property @{
    ComputerName = $Computer.ToUpper();
    TimeGenerated = $event.TimeGenerated;
    EntryType = $event.EntryType;
    Source = $event.Source;
    Message = $event.Message;
    $column1 = @{expression="ComputerName"; width=12; label="ComputerName"; alignment="left"}
    $column2 = @{expression="TimeGenerated"; width=22; label="TimeGenerated"; alignment="left"}
    $column3 = @{expression="EntryType"; width=10; label="EntryType"; alignment="left"}
    $column4 = @{expression="Source"; width=15; label="Source"; alignment="left"}
    $column5 = @{expression="Message"; width=100; label="Message"; alignment="left"}
    $Object|format-table $column1, $column2, $column3 ,$column4 ,$column5
    $Object.GetEnumerator() | Out-GridView -Title "Event Viewer"
    You can do a function call like
    Get-EventViewer -LogName system -ComputerName "computername" -eventid "2017"

  • Date / Time Range Selection

    Post Author: LDFCC
    CA Forum: Formula
    I am trying to create a report using Crystal Report XI which prompts the user to enter a start date / end date / start time & end time. For example, the person will select 9/19 (start date), 9/20 (end date), 10 AM (Start time), 10:30 AM (End Time). The report correctly pull up all tickets from 9/19 till 9/20 but only displays the tickets from 9/19 from 10 - 10:30 AM and 9/20 from 10 - 10:30 AM. I need it to show all tickets from 9/19 10:00 AM till 9/20 10:30 AM. Both the time and date are two seperate fields in the database. Any help is greatly appreciated.
    Thanks.

    Post Author: LDFCC
    CA Forum: Formula
    yangster:
    since you are dealing with 2 seperate fields for date and time the first thing you want to do is merge them back into one so things are consistenttry putting this in your selection expert
    datetimevar begin_date_time := datetime(cdate(?begin date), ctime(?begin time));datetimevar end_date_time := datetime(cdate(?end date), ctime(?end time));datetime(cdate(date_field), ctime(time_field)) in begin_date_time to end_date_time
    I tried this and I get an error because it says that (?begin date), (?begin time), (?end time), and (?end date) all have to be date time fields but they are not the date field is only date field and same with the time fields. Any suggestions?

  • Query Based on Date & Time Range

    Hello Users,
    There is a requirement to display weekly report from saturday 8:00 AM to previous saturday 08:00 AM.
    I have a table "Downtime"
    IPADDRESS       First Occurrence                   Last Occurrence           Downtime
    172.29.10.12    31-JUL-10 08:12:50             01-AUG-10 09:00:00      1
    172.29.11.54    01-AUG-10 11:12:00            01-AUG-10 01:10:00      3
    172.29.58.7      07-AUG-10 04:10:00            07-AUG-10 05:00:00      2I will not have problem when I run the report on saturday as I can give condition as sysdate - 7.
    First problem is how will I default to 8 AM.
    Second if the report is run on sunday or in between before next saturdya I have to query the records only from satuday 8 AM to previous saturday 8 AM.
    Can anyone please help me on this?
    Thanks.
    Ravi.

    Hi,
    hoek wrote:
    That's a great hint, Solomon, thanks.
    I always end up getting frustrated because trunc on a date returns a NULL for 'midnight'....and the ability to perform date arithmetic is gone all of a sudden. Why isn't Oracle just resetting to '00:00:00' when truncating a date, I wonder?I must not understand what you're asking.
    It sounds as if you're saying that TRUNC (dt) sometimes returns something that is NULL (or somehow partially NULL), but I'm sure you don't really think that.
    For other readers who may be wondering:
    TRUNC (dt), where dt is a DATE (and not NULL) , always returns a DATE, and DATEs always have a time. Either the whole DATE is NULL or none of it is; you can't have a year-month-day in a DATE column and not have a time, or have a NULL time.
    TRUNC(dt, x) may return a DATE where the time is not midnight, but only if x is a format string like 'MI' that specifies an interval less than a day. When x indicates a longer interval (e,g, 'IW'), or when x is omitted, the time is always midnight. In any event, you can do date arithmetic on the results.
    I'm sure you understand this, but your question makes it sound like you don't.
    This should illustrate my point:
    -- generating hours, starting 14 days ago:
    with t as (
    select trunc(sysdate-14)+ level/24-1 dt
    from   dual
    connect by level <= 24*14
    -- querying generated data:
    select dt
    --,      trunc(dt,'iw') - 5/3  -- great workaround, but why can't we just work with 00:00:00 for the time component?
    from   t;
    -- generating hours, starting 14 days ago:
    with t as (
    select trunc(sysdate-14)+ level/24-1 dt
    from   dual
    connect by level <= 24*14
    -- querying data between saturday and previous saturday
    -- from the same resultset and 'it doesn't work'
    select dt
    from   t
    where  dt between trunc(dt-7)+8/24 and trunc(sysdate)+8/24;
    Is this a parody of a poorly written question?
    Are you trying to make the point that no one should ever say "it doesn't work" without explaining exactly what doesn't work, and what the expected output is?
    I get the same 336 rows when I run either of the queries above.
    As you've often said, posters should always show exactly what results they want.

  • How to select data, based on a specified or preset date/time range

    Hi,
    I am trying to construct a requirement like this in java/jsp.
    I have a table consisting of registered users info. Have a expiration date for every user, which was captured or set when they originally registered.
    I have to select all those users who are expiring two weeks from now.
    For example. if the current date is 14th, I should get a list of users who expire between the midnight of 24th sunday to 30th saturday. this covers the whole last 7days in that range. And so on.
    So based on the current date, the last midnight sunday to midnight saturday of that two week's range should be selected.
    The input fields for this range on the userend should default to this range.
    And also the user should be able to specify their own range and be able to pull data.
    the result should be populated as viewable as well as a downloadable tab de-limited file for mass mailing.
    (ex. the table might be queried for user info like id, email, expiration date, fullname, and shown accordingly in the jsp)
    I know this is a longshot.. but if somebody can guide me will be good as I am new to this forum and as well as java.

    Well, I can start you off with this:
    Calendar now = Calendar.getInstance();
    // shift 2 weeks and back to Sunday
    Calendar start = Calendar.getInstance();
    start.add(Calendar.DATE, 14);
    end.set(Calendar.HOUR, 0);
    end.set(Calendar.MINUTE, 0);
    end.set(Calendar.SECOND, 0);
    end.set(Calendar.MILLISECOND, 0);
    while(start.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
    start.add(Calendar.DATE, -1);
    // shift 2 weeks and up to Saturday (following Sundat midnight, actually)
    Calendar end = Calendar.getInstance();
    end.add(Calendar.DATE, 14);
    end.set(Calendar.HOUR, 0);
    end.set(Calendar.MINUTE, 0);
    end.set(Calendar.SECOND, 0);
    end.set(Calendar.MILLISECOND, 0);
    while(end.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
    end.add(Calendar.DATE, -1);
    At this point, start is the first Sunday before the day 2 weeks from today and end is the first Sunday after the day 2 weeks from today, both at midnight. You could make end stop at Saturday and make the time 23:59:59:999, of course.
    If you ran it today, it should be 11/9 and 11/16.

  • Will 'Event' in the timeline support "Date/Time Range" and "Location"?

    Currently the 'Event' seems to be limited in a simple one day event as well as not able to specfiy a location(using description is a workaround). I am wondering if it will be supported in the futrure. I am it's a good to have since Streamwork is on the mobile device(iphone) already.

    Hi,
    Enhancements to the timeline are planned: you can check for yourself at http://feedback.streamwork.com/forums/11095-sap-streamwork/suggestions/409174-timeline-should-support-multi-day-events?ref=title. If you have additional enhancment request just go ahead and submit them via the "Feedback" button on the right of StreamWork. You can also vote for already entered enhancemetn request.
    Regards, Rüdiger

  • Datalogging with options to retrieve subset of log file based on date/time

    I would like to thank this forum for useful advice so far in completing my LabVIEW software.
    I have a data logging challenge. I am supposed to log about 30 parameters every 5 seconds. Some of these parameters are digital (ON/OFF), some are values of speed (rpm) and others, an expression of a percentage (%). It should be possible in future to do a histogram or bar chart plot of some of the parameters, for a specific period range (say the last 5 minutes of a certain day). So in effect, do an extraction of a segment of the total log file.
    My challenge is if I use text file, like the one in the attached VI, can it give functionality of retrieving data (while the VI is running) from the log file, based on a certain time range (i.e. retrieve a section of the log file based on a certain date/time range, on demand)?
    The format in the text file is close to what I require, since it lists the time n one column and the other parameters on other columns to enable future histogram generation.
    Thanks a lot, friends.
    Solved!
    Go to Solution.
    Attachments:
    writer.vi ‏19 KB
    time.txt ‏1 KB

    Hey maxidivine,
    Iv been playing round with your code and found that to perform the search that you require could be quite demanding to system resources when scaled to the size of your application I shall try and find a way to perform the search using .txt files but the there are some other options available. I recommend the use if TDMS files as the file format is a very efficient, manageable method of data-logging. The TDMS file format is designed to write and read measured data at a very high speed, while maintaining a hierarchical system of descriptive information.
    Traditionally, TDMS was a National Instruments only file format – you could only read it using our products – LabVIEW/CVI/DIAdem. However, thanks to the popularity of the format, a bolt-on is now available for Excel, which allows you to directly open the .tdms files with Excel (see link).
    National Instruments Technical Data Management Overview
    http://zone.ni.com/devzone/cda/tut/p/id/3676
    Introduction to LabVIEW TDM Streaming Vis
    http://zone.ni.com/devzone/cda/tut/p/id/3539
    VI-Based API for Writing TDMS Files
    http://zone.ni.com/devzone/cda/tut/p/id/6471
    TDM Excel Add-In Tool for Microsoft Excel User Guide
    http://zone.ni.com/devzone/cda/tut/p/id/4906
    TDM Excel Add-In for Microsoft Excel Download
    http://zone.ni.com/devzone/cda/epd/p/id/2944
    Troubleshooting the TDM Excel Add-In for Microsoft Excel 2000-2003
    http://zone.ni.com/devzone/cda/tut/p/id/5874
    Examples of the use of the TDMS API ship with LabVIEW. You will find them in HELP > find examples > fundamentals > File Input and Output. For you application, I would recommend the “Cont Acq&Graph Voltage - Write Data to File (TDMS).vi”.
    Furthermore, if you require some help with DIAdem, I would recommend clicking "getting started" from the DIAdem splash screen. This opens a manual which discusses everything from data analysis to report generation. Also, if you have DIAdem 11 or above, there are tutorial videos which install with DIAdem. These are useful little tutorials, which discuss all the DIAdem fundamentals. You can access these by selecting a particular palette tab (eg. report, view, analysis...etc) and then clicking the tutorial button (shown as a film strip with a question mark) at the top of the group view.
    Here are some more helpful DIAdem related resources for future reference.
    Report Gen in DIAdem...
    http://zone.ni.com/devzone/cda/tut/p/id/7379
    DataPlugins: Supported Data Formats (ni.com/dataplugins)
    http://zone.ni.com/devzone/cda/tut/p/id/4065
    Hope this is helpful
    Philip
    Philip
    Applications Engineer
    National Instruments
    UK Branch
    ===If this fixes your problem, mark as solution!===

  • Oracle 8i - select between to date ranges, but exculde time ranges

    Hi, I'm using Oracle 8i
    I'm trying to select a set of records that are between a certain date time (say between October 15 at 6pm and October 17 at 6am) and then want to include only those records that fall between 6am and 6pm within the range.
    I've tried extract and trunc function and can't seem to get it to work.
    If I do a trunc to try to pull out only hour, it returns all of the date information as well:
    SQL> select trunc(to_date('14-10-2007 02:43:46','DD-MM-YYYY HH24:MI:SS'),'HH24') from dual;
    TRUNC(TO_DATE('14-10
    14-OCT-2007 02:00:00
    SQL>Any Ideas? Here is some sample data:
    select * from
            select to_date('14-10-2007 02:43:46','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('14-10-2007 03:02:50','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('14-10-2007 15:13:16','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('14-10-2007 15:16:04','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('14-10-2007 15:18:26','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('14-10-2007 15:20:25','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('14-10-2007 15:22:35','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('14-10-2007 15:23:59','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('14-10-2007 15:26:30','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('14-10-2007 15:33:30','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('14-10-2007 15:54:36','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('14-10-2007 15:56:11','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('14-10-2007 18:56:52','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('15-10-2007 09:12:38','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('15-10-2007 10:23:42','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('15-10-2007 11:17:32','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('15-10-2007 11:46:12','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('15-10-2007 12:36:22','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('15-10-2007 23:23:17','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('16-10-2007 14:43:06','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('16-10-2007 14:44:37','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('16-10-2007 14:48:17','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('16-10-2007 14:49:36','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('16-10-2007 15:07:05','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('16-10-2007 15:08:24','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('17-10-2007 08:55:33','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('17-10-2007 09:58:19','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('17-10-2007 15:07:16','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('17-10-2007 15:19:35','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('17-10-2007 15:58:32','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('17-10-2007 19:56:51','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('17-10-2007 21:22:49','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('17-10-2007 22:16:52','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('17-10-2007 22:45:51','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('18-10-2007 07:52:10','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('18-10-2007 07:54:15','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('18-10-2007 08:03:57','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('18-10-2007 08:31:27','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('18-10-2007 09:16:14','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('18-10-2007 11:10:55','DD-MM-YYYY HH24:MI:SS') from dual union all
            select to_date('18-10-2007 11:21:57','DD-MM-YYYY HH24:MI:SS') from dual
    ) DataSet

    If you can subtract date types from each other in 8i (I think you can but don't know for sure) you can use this:select dte, (dte-trunc(dte))*24 hours
    from (SELECT TO_DATE('15-10-2007 05:59:59',    'DD-MM-YYYY HH24:MI:SS') DTE FROM DUAL UNION ALL
       SELECT TO_DATE('15-10-2007 06:00:00',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('15-10-2007 06:00:01',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('15-10-2007 17:59:59',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('15-10-2007 18:00:00',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('15-10-2007 18:00:01',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('16-10-2007 05:59:59',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('16-10-2007 06:00:00',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('16-10-2007 06:00:01',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('16-10-2007 17:59:59',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('16-10-2007 18:00:00',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('16-10-2007 18:00:01',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('17-10-2007 05:59:59',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('17-10-2007 06:00:00',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('17-10-2007 06:00:01',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('17-10-2007 17:59:59',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('17-10-2007 18:00:00',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL UNION ALL
       SELECT TO_DATE('17-10-2007 18:00:01',    'DD-MM-YYYY HH24:MI:SS') FROM DUAL
       ) t
    where dte between TO_DATE('15-10-2007 18:00:00',    'DD-MM-YYYY HH24:MI:SS')
                  and TO_DATE('17-10-2007 06:00:00',    'DD-MM-YYYY HH24:MI:SS')
          and (dte-trunc(dte))*24 between 6 and 18
    DTE                       HOURS                 
    15-OCT-2007 18.00.00      18                    
    16-OCT-2007 06.00.00      6                     
    16-OCT-2007 06.00.01      6.00027777777777777777777777777777777778
    16-OCT-2007 17.59.59      17.99972222222222222222222222222222222222
    16-OCT-2007 18.00.00      18                    
    17-OCT-2007 06.00.00      6                     
    6 rows selected

  • How to identify date & time of insertion of rows in a table

    Hi,
    Is it possible to identify the date & time of insertion of rows in a table?
    for example:
    Table name: emp
    I have rows like this
    emp_code name dept
    pr01 ram edp
    ac05 gowri civil
    pr02 sam pro
    i want to know the date and time of the insertion this( ac05 gowri civil).
    Could you please help me.....
    Thanks in advance....

    psram wrote:
    sorry for the confusion. I dont want to store date and time. I said that for example only.
    I have table which consists of thousands of rows. I want to know the insertion date & time of a particular row.
    Is it possible?So, if I have a table that stores a load of employee numbers, do you think I could get the database to tell me their names?
    If you don't store the information, you can't query the information.
    Ok, there are some dribbs and drabbs of information available from the back end of the database via the SCN's, Archive Logs etc., but those sort of things disappear or get overwritten as time goes by. The only way to know the information it to ensure you store it in the first place.
    So, in answer to your question, No, there isn't a true and reliable way to get the data/time that rows were inserted into the table, unless you have chosen to store it alongside the data.

  • Can please tell me how to implement expand and collapse table row data?

    i am trying implement expand and collapse table row data but i do not get any ideas..can please any one help me its an urgent requirement

    Yes, we can.   
    I think the best place for you to start for this is the NI Developer Zone.  I recommend beginning with these tutorials I found by searching on "data log rio".  There were more than just these few that might be relevant to your project but I'll leave that for you to decide.
    NI Compact RIO Setup and Services ->  http://zone.ni.com/devzone/cda/tut/p/id/11394
    Getting Started with CompactRIO - Logging Data to Disk  ->  http://zone.ni.com/devzone/cda/tut/p/id/11198
    Getting Started with CompactRIO - Performing Basic Control ->  http://zone.ni.com/devzone/cda/tut/p/id/11197
    These will probably give you links to more topics/tutorials/examples that can help you design and implement your target system.
    Jason
    Wire Warrior
    Behold the power of LabVIEW as my army of Roomba minions streaks across the floor!

  • Discrete time range over date range  (using CR X1)

    Post Author: sjr
    CA Forum: Formula
    Can anyone show me how to select data over a discrete time range i.e. 6 p.m. till 11 p.m. per day, over a period of a month ?
    Using the data time parameter gives me data from 6p.m. on startdate right through till 11p.m. on endate.

    Here's a more detailed description...
    Create two formula fields to split the date and time from the data records (ds prefixed):
    dsDate
    dsTime
    Create two formula fields to split the date and time from the parameter fields (pm prefixed):
    pmStartDate
    pmStartTime
    pmStartDate
    pmStartTime
    Use your new formula fields in the record selector. Get to this off the Report menu button (in CR 2008):
    Report | Select Expert... | Record.
    You can pick the formula fields in the Forumula Editor to create something like:
    ({@dsDate} > {@pmStartDate} and
    {@dsDate} < {@pmEndDate}) and
    ({@dsTime} > {@pmStartTime} and
    {@dsTime} < {@pmEndTime)
    Tim

  • How can I set a date range for a Date/Time Field in LiveCycle ES2?

    I need to set a specific date range for a form set up in LiveCycle ES2. Cannot see where i allows me to do that without a code entered.

    Hi,
    You can't set a start and end date for the date/time field, the best you can do is validate the range after the user has selected it.
    An alternate is to make your own date / time field, like this sample http://adobelivecycledesignercookbookbybr001.blogspot.com.au/2013/05/an-alternative-date-p icker-for.html
    Regards
    Bruce

  • JSF Datatable row data - Expand/Collapse

    Hi,
    I just started learning the JSF concepts. I read articles by BalusC which are very clear and easily understandable. Thanks to BalusC.
    I have a requirement to implement expand and collapse data using JSF datatable. The data comes from the backing bean is in the form of java.util.List which contains StudentInfo. I will have to display following data from the list.
    *{color:#0000ff}name {color}(this is to be displayed a link), firstname, lastname, dob*
    I am able to display the data in a nice formatted table using h:datatable. My main hurdle is to display an expanded info when the name link is clicked. The expanded info should be displayed below the row spanning all columns. The additional info being the comments, instructions whic are the part of the row data. Here is the code describing the StudentInfo.
    Appreciate if someone help me with suggestions. Very helpful if any sample code is avaialble.
    Regards,
    Smitha
    public class StudentInfo {
    //Following fields to be shown in row data
    private String name;
    private String firstname;
    private String lastname;
    private String dob;
    //Following fields to be shown in expanded form
    private String comments;
    private String instructions;
    public String getName() {
    return name;
    public void setName(String name) {
    this.name = name;
    public String getFirstname() {
    return firstname;
    public void setFirstname(String firstname) {
    this.firstname = firstname;
    public String getLastname() {
    return lastname;
    public void setLastname(String lastname) {
    this.lastname = lastname;
    public String getDob() {
    return dob;
    public void setDob(String dob) {
    this.dob = dob;
    public String getComments() {
    return comments;
    public void setComments(String comments) {
    this.comments = comments;
    public String getInstructions() {
    return instructions;
    public void setInstructions(String instructions) {
    this.instructions = instructions;
    }

    That's not possible with plain h:dataTable.
    Consider Tomahawk t:dataList where in you can specify rows and colspans yourself using plain HTML. Show/hide rows should be easy with JavaScript.

  • Time difference by date by time range - a better way?

    Someone suggested this is a better place for my question:
    Hi
    I need to display the difference in time - every day for different time ranges,
    Example 1-2 pm, 4-5 pm, 7-8 pm. And I need the time difference in 2 dates in the past week for each of these ranges everyday.
    example
    Date Diff Range
    01/01/2007 00:01 1-2pm
    01/02/2007 00:03
    01/03/2007 00:10
    01/04/2007 00:05
    01/05/2007 00:23
    01/01/2007 00:10 4-5pm
    01/02/2007 00:13
    01/03/2007 00:11
    01/04/2007 00:15
    01/05/2007 00:23
    01/01/2007 01:10 7-8pm
    01/02/2007 00:13
    01/03/2007 00:10
    01/04/2007 00:11
    01/05/2007 00:21
    One way to achieve this is to have multiple unions for each day and each time range.
    Example:
    select
    from
    where dt_tm between
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 13:00','mm/dd/yyyy hh24:mi:ss')and
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 14:00','mm/dd/yyyy hh24:mi:ss')
    union
    select
    from
    where dt_tm between
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 16:00','mm/dd/yyyy hh24:mi:ss')and
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 17:00','mm/dd/yyyy hh24:mi:ss')
    union
    select
    from
    where dt_tm between
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 19:00','mm/dd/yyyy hh24:mi:ss')and
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 20:00','mm/dd/yyyy hh24:mi:ss')
    This will give me the required information for only one day - and that is for sysdate-5.
    I will have same nyumber of unions for each day.
    Is there a better way to accomplish the same?
    Any help appreciated.
    Thx!

    Hi
    Sorry for the late response but better late than never:::
    I have gotten the answer of getting data for previous 5 days. I have changed the time between statement and is given below(*).
    Here is a reply to all the questions you had asked in response to my questions.
    What data you have? What parameters are you going to input?
    I have already given sample data in my post.
    There are no input parameters.
    You are talking about the difference - between what is this difference?
    Difference is the difference between 2 timestamp datatypes in 2 different tables (as you may see in the query)
    The field diff - is it varchar2 like '1-2 pm' or what?
    I didnt understand your question. What do you get when you subtract two timestamp datatypes - that should be the datatype - if I have understood your question. Not sure if thats what you asked.
    But IMHO it's impossible to get such a result, of course, if dt_tm in the query is the same as Date in the result!
    The time components in the queries are different. If you see:
    1st Query:...
    where dt_tm between
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 13:00','mm/dd/yyyy hh24:mi:ss')and
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 14:00','mm/dd/yyyy hh24:mi:ss')
    2nd Query:....
    where dt_tm between
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 16:00','mm/dd/yyyy hh24:mi:ss')and
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 17:00','mm/dd/yyyy hh24:mi:ss')
    3rd Query:
    where dt_tm between
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 19:00','mm/dd/yyyy hh24:mi:ss')and
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 20:00','mm/dd/yyyy hh24:mi:ss')
    First should be between 1 and 2 pm for sysdate-5.
    I need starting previous 5 days till sysdate.
    Second is between 4 and 5 pm again for sysdate-5.
    I need starting previous 5 days till sysdate.
    Same with 3rd.
    My final query is something like this:
    select t1.dt_tm, count(t1.id), '1 - 3 am' as period
    from table1 t1, table2 t2
    where t1.id = t2.id
    and dt_tm between
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 13:00','mm/dd/yyyy hh24:mi:ss')and
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 14:00','mm/dd/yyyy hh24:mi:ss')
    group by t1.dt_tm
    union
    select t1.dt_tm, count(t1.id), '4 - 5 pm' as period
    from table1 t1, table2 t2
    where t1.id = t2.id
    and dt_tm between
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 16:00','mm/dd/yyyy hh24:mi:ss')and
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 17:00','mm/dd/yyyy hh24:mi:ss')
    group by t1.dt_tm
    union
    select t1.dt_tm, count(t1.id), '7 -8 pm' as period
    from table1 t1, table2 t2
    where t1.id = t2.id
    and dt_tm between
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 19:00','mm/dd/yyyy hh24:mi:ss')and
    to_date(to_char((sysdate-5),'mm/dd/yyyy')||' 20:00','mm/dd/yyyy hh24:mi:ss')
    group by t1.dt_tm
    I need for the last 5 days and what i can think of is have 5 different queries for past 5 days and 3 queries per day for the 3 different time periods. This would mean 15 queries. Was wondering if there is a better way to achieve the same?
    Any help appreciated.
    Thx!

  • Min,Max for a time Range and Sum of Records for the last date/time

    Hi All,
    I have a table with the following structure/data:
    create table  Events   (
                                        [EventID]       
    int                   NOT NULL,
                                        [Title]            
    nvarchar(200)  NOT NULL,
                                        [SourceName]  nvarchar(20)    NOT NULL,
                                        [Type]             
    int                  NOT NULL,
                                        [eDate]           
    datetime
    insert into Events values(100, 'Event 1', 'S01', 3,'2014-01-01 00:00:00.000')
    insert into Events values(100, 'Event 1', 'S07', 3,'2014-01-01 00:00:00.000')
    insert into Events values(100, 'Event 1', 'S08', 3,'2014-01-01 00:00:00.000')
    insert into Events values(100, 'Event 1', 'S09', 3,'2014-01-01 00:00:00.000')
    insert into Events values(101, 'Event 2', 'S010', 3,'2014-01-01 00:00:00.000')
    insert into Events values(102, 'Event 3', 'S03', 3,'2014-01-01 00:00:00.000')
    insert into Events values(100, 'Event 1', 'S04', 3,'2014-01-01 00:00:00.000')
    insert into Events values(101, 'Event 2', 'S05', 3,'2014-01-01 00:00:00.000')
    insert into Events values(102, 'Event 3', 'S06', 3,'2014-01-01 00:00:00.000')
    insert into Events values(100, 'Event 1', 'S01', 3,'2014-02-01 00:00:00.000')
    insert into Events values(101, 'Event 2', 'S02', 3,'2014-02-01 00:00:00.000')
    insert into Events values(102, 'Event 3', 'S03', 3,'2014-02-01 00:00:00.000')
    insert into Events values(100, 'Event 1', 'S04', 3,'2014-02-01 00:00:00.000')
    insert into Events values(101, 'Event 2', 'S05', 3,'2014-02-01 00:00:00.000')
    insert into Events values(102, 'Event 3', 'S06', 3,'2014-02-01 00:00:00.000')
    insert into Events values(100, 'Event 1', 'S01', 3,'2014-03-01 00:00:00.000')
    insert into Events values(101, 'Event 2', 'S02', 3,'2014-03-01 00:00:00.000')
    insert into Events values(102, 'Event 3', 'S03', 3,'2014-03-01 00:00:00.000')
    insert into Events values(100, 'Event 1', 'S04', 3,'2014-03-01 00:00:00.000')
    insert into Events values(101, 'Event 2', 'S05', 3,'2014-03-01 00:00:00.000')
    insert into Events values(102, 'Event 3', 'S06', 3,'2014-03-01 00:00:00.000')
    And I wrote the following query:
     select EventID as [Event ID],
           Title, 
           count(distinct(SourceName)) as [Instances], 
           Type,
           min(eDate) as  [First Detected],
           max(eDate) as [Last Detected],
           datediff(d,min(eDate),max(eDate)) as [Delta (days)]
    from  Events
    where type = 3
    group by EventID, Title, Type
    having max(eDate) <> min(eDate)
       and max(eDate) =(select top 1 eDate from Events order by eDate desc)
    and I get the following results (see the instance number)
    Event ID Title         Instances Type First Detected                      Last Detected                    
       Delta (days)
    =============================================================================================================================
    100         Event 1         5         3    2014-01-01 00:00:00.000     2014-03-01 00:00:00.000    
    59
    101         Event 2        
    3         3    2014-01-01 00:00:00.000     2014-03-01 00:00:00.000     59
    102         Event 3        
    2         3    2014-01-01 00:00:00.000     2014-03-01 00:00:00.000     59
    This is normal for this query however what I need to do is a little different.
    In other words, while I need to show when we recorded a specific event first and last time,
    I need to display the results for the last date/time when it was recorded. 
    For example what I need to provide should look like this:
    Event ID  Title                Instances        Type       First Detected                    
    Last Detected                          Delta (days)
    =============================================================================================================================
    100         Event 1            2                   3           
    2014-01-01 00:00:00.000     2014-03-01 00:00:00.000      59
    101         Event 2            2                   3           
    2014-01-01 00:00:00.000     2014-03-01 00:00:00.000      59
    102         Event 3           
    2                   3            2014-01-01 00:00:00.000     2014-03-01 00:00:00.000     
    59
    Could you please help me to fix this query?
    TIA,
    John

    ;With cte As
    (Select EventID as [Event ID],
    Title,
    SourceName,
    Type,
    min(eDate) Over(Partition By EventID, Title, Type) as [First Detected],
    max(eDate) Over(Partition By EventID, Title, Type) as [Last Detected],
    eDate,
    datediff(d,min(eDate) Over(Partition By EventID, Title, Type),max(eDate) Over(Partition By EventID, Title, Type)) as [Delta (days)],
    max(eDate) Over() As MaxEDate
    from Events
    where type = 3)
    Select [Event ID],
    Title,
    COUNT(Distinct SourceName) As Instances,
    Type,
    [First Detected],
    [Last Detected],
    [Delta (days)]
    From cte
    Where eDate = MaxEDate And [First Detected] <> [Last Detected]
    Group By [Event ID],
    Title,
    Type,
    [First Detected],
    [Last Detected],
    [Delta (days)];
    Tom
    P.S. Thanks for providing the DDL and data.  That is always very helpful.

Maybe you are looking for