Obtaining Min/Max for Day Summary Across Midnight

Hi there,
Have a bit of an interesting problem.
I would like summaries in the form of
Date, SESSIONA_Maximum, SESSIONA_Minimum, SESSIONB_Maximum, SESSIONB_Minimum
I have two dimensions, Date and Time. Day represents levels at Day, Week, Month, Qtr, Year. Time is Hour, Minute, Second.
An example of Session A would be that it starts at June 27th at 4:30PM and ends at June 28th 9:30AM. Session B would start at 9:30AM and end at 4:15PM.
As you can see session A starts on one day and ends on the next. And I would like to combine it's summary on the next day since this is when Session B will start and end. How can I go about accomplishing this?
Ideally, I'd like the ability to add another dimension which corresponds to the times of Session A or Session B because I will have many calculations that are the same, but will have to be independently applied to either Session A or Session B. Some will also have to be applied to both.

Since there is some context missing, I don't get everything, but from your narrative, it seems likely you need something like:
WITH CTE AS (
   SELECT keycol,
          period = CASE WHEN Start < '12:00' THEN 'AM'
                        WHEN Start < '17:00' THEN 'PM'
                        ELSE 'EVE'
                   END,
          start, stop
   FROM   tbl
SELECT keycol, period, MIN(start), MAX(stop)
FROM   CTE
GROUP  BY keycol, period
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • Want to set Min Max for a material for PD MRP type

    Hi,
    I know Maximum stock level field in Material master MRP 2 view ? but where do i maintain minimum stock level? not procured?
    My client wants to set up his inventory with Min Max levels using MRP PD?
    Thanks and Apprecaites help.
    Regards,
    Siva

    Hi,
    If you want to maintain a Max and Min stock level, Maximum stock is shown straight away, you cannot find the Minimum field directly.
    if you want to use MRP type PD then go for safety stock that will be your minimum stock level
    or else use Re-order point planning, re-order point will be your minimum and Max-level as maximum.
    Thanks
    Satya

  • Can I set the min/max for multiple images at once?

    I have brought in my page design from photoshop and I don't want any of the images or text to resize when the web browser window is made smaller.
    Is there a way to do this without setting each min & max individually?

    I answered my own question in the end, I moved them to the parent background

  • 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.

  • Min/max MRP and double star planned order

    Hi,
        What does setting up materials for min/max mean ? Is it just some concept r does it involve some specific settings in the material master ? I know there are minimum and maximum lot sizing procedures available. Are these to be taken into account to set materials up for min/max ?
    What does a planned order with two stars in the MD04 screen mean?
    Thanks

    Dear,
    Single *** means order is Firmed and **** means Capacity planning has been done for the  planned order.
    There is "storage location" MRP with min max levels.
    Have a look at the fields on the MRP screens in the material master and you will see the settings you can choose from.
    There should be no need for any config as long as your basic MRP config is there.
    The normal MRP run will then try to maintain the correct stock level in that storage location and you use the special procurement keys on the material master to determine where the stock should come from to replenish that storage location.
    Go to TcodeOMIA  here you will find min max for your plant.
    Regards,
    R.Brahmankar

  • Can we use MRP to plan for FERT in-house produced  with PIR's & has Min/Max

    Hi SAP Guru's
    I have a very critical issue from the client who wants to use MIN/ MAX stock values for planning its finished products (in-house produced)
    <b>here is the details of the scenario</b>
    Client recieves 2 Excel files every week from customer
    <b>1st</b> file contains the Weekly Demand Forecast of FERT material for next 1 year and they upload it in MD61 as PIR's <u><b>BUT</b></u> this value is also <u><b>Inclusive</b></u> of Safety stock value (<b>ex: if weekly demand entered in MD61 as PIR is 50 and if safety stock value is 10, then actual demand is only 40)</b>
    <b>2nd</b> file send contains only <b>safety stock values</b> (for ex in this case let it = <b>10</b>) to be maintained for the FERT materials
    the client wants MRP to plan and trigger based on this PIR's in MD61 and Safety stock level fand plan for FERT, HALB and also ROH materials as defined in the BOM also taking into consideration the current WIP levels (Work in progress for any existing production orders currently being processed) based on the production Lead times values maintained
    so what the client wants is they want to maintain 2 stock values, that is one least stock value and other higher value which if stock falls below this point, will trigger production based on the lead time and considering any WIP levels also
    <b>(for ex in this case if PIR = 50 and safety stock is 10, MRP run result client wants is = 30 and NOT =40)</b>
    so here are my questions
    1. is this scenario feasible? use safety stock and min/max level for in-house produced finished which has demand PIRs in MD61 at the same time?
    2. Also due to SOX complaince regulations, the client does not want to change the forecast values in MD61, so is it possible to make some settings so that forecast is corrected by WIThOUT including the safety stock value in it? ( for ex: in this case as = 40 only and NOt as 50)
    3. which all settings should i maintain like for MRP type or lot size or stock qty levels or anyother customizations if any required so that when we run MRP, can it ignore the safety stock value and generate the client desired output?
    thank u verymuch for your time & expert advice in advance

    Hi Chakri,
    This is not possible as per standard functionality. MRP always creates proposals for the shortage quantity of the safety stock. We have used the user exit in the plant level MRP run to exclude both plant and safety stock in the net requirements calculation.
    You have to write logic to convert the safety stock into plant stock in the user exit so there will be no additional procurement proposals...you can create custom indicatar in materail master or linked any existing indicator like MRP group to the user exits so the MRP will checks this and will not create proposals for the selected parts.
    If you have any questions then please inform.
    Regards
    TAJUDDIN

  • Vendor details for a Min Max requisitions

    Hi All
    When Min Max trigger some requisition interface lines, we need to get the vendor details also be populated,
    What set up it need to get these. Because when I run a Min-Max planning report, I am not getting the vendor details.
    What we have is we will be having a single item be with a single vendor and vendor site
    Please help.

    In the General planning tab for Sourcing type is it mentioned as Supplier?
    Is the use ASL flag in the Purchasing tab for the item enabled?
    The supplier and site details are active?
    The ASL for this item is still active ? (Check in the supplier line details in the ASL form)
    My funtional guy says yes to all the above quries.
    And also says All ASL have the sourcing rules assigned to the assignment set that is setup on the MRP: Default Sourcing Assignment Set profile, but this scenario is only for minmax
    So this issues is only for MIN-MAX.Please let me know if any thing to be done in setup to automatically get the
    vendor details into requistions lines of interface table based on items.
    Edited by: 834095 on Mar 14, 2011 2:59 AM

  • MRP creating cancel notices for min max purchased items

    We use min max planning for many repetitive purchased items. These same items are also set to MPS/DRP Planned as well. This is only so we can use the Planned Order report to identify material shortages to flow schedules.
    However, MRP exceptions is requesting we cancel our min max purchased items since there is no demand. Can MRP be modified to NOT include min max planning method in cancel requests?
    If not, where can I find a tool to identify material shortages for flow schedules?

    Many thanks for this.
    I can see entirely why it's designed as such, but I just find it slightly frustrating that there's no way to break the link between the order and the shipment out to the depot. Just to clarify, we're not requiring the orders to change - they will still be made and will come in - but just that the orders themselves don't specifically need to be the stock that is used for the replenishment.
    So -
    1. Min Max identifies depot needs replenishing.
    2. Central distribution does not have (enough) stock to replenish.
    3. Order is made to replenish central distributions stock.
    4. We ship whatever we've got, when we've got it, to depot to replenish.
    It's the bit where Min-Max is trying to replensih a specific depot rather than our central distribution centre that's my problem.
    I suspect that, as you say, that specific issue is not directly fixable without getting our IT contractors to do a customisation.
    I'm going to look into your Supply Date Offset suggestion now, though I'm not sure how this affects the shipping after the orders are placed. The orders themselves are approved manually after we've checked our stock position (i.e. what's in with the recycling team), but we recycle & refurb probably 60% of our maint stock so there'll always be kit turning up after the order has been made because of the long lead times.
    Thanks again.

  • Min/max temperatires for all stations on computer.

    iMac, Intel 2/2, 6mb, L2Cache_4g, 1.33ghz, 10.6.8 Snow Leopard
    I've lately become aware of the presence of a temperature report on my Dashboard and wonder where I can find the Min/Max status for all my heat situations.
    .....goldie

    Anyone able to help with this?
    Regards
    Richard

  • Min Max planning report - ability to run for specific vendor

    Hi,
    We have a unique requirement wherein business users would like to run min-max planning report for a specific vendor. Vendor here is item sourcing vendor. We are on R12 12.0.4. This version of applications doesnot support sourcing vendor as the min-max report parameter.
    Other than setting up item category for ASL vendor, i can't think of any other easy way to accomplish above requirement. Please suggest workaround for above requirement.
    Thank you

    If you have to do this, here is a complex workaround.
    Create a request set that contains a custom program as first stage and the regular min-max as the second stage.
    The custom program accepts vendor name as a parameter and disables min-max planning flag for all items EXCEPT those that are sourced from that vendor.
    Then the 2nd stage runs and creates requisition.
    You may add a 3rd stage that resets the min-max planning flag.
    Make this program incompatible with itself so 2 users won't run it at the same time.
    Hope this helps,
    Sandeep Gandhi

  • Get min and max for a column from table with 24 million rows.

    What is the best way to re-write the following query in a procedure for the table which has around 24 million rows?
    SELECT MIN(ft_src_ref_id), MAX(ft_src_ref_id )
    INTO gn_Min_ID, gn_Max_ID
    from UI_PURGE_FT;
    Thanks
    Edited by: tcode on Jun 21, 2012 12:31 PM

    Which of the following plan is better, can you please breifly explain?
    Also I need to gather statics to know recursive calls , db block gets ,consistent gets etc. etc. how can I get that?
    Thanks
    1.
    Execution Plan
    Plan hash value: 3702745568
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 6 | 13991 (2)| 00:02:48 |
    | 1 | SORT AGGREGATE | | 1 | 6 | | |
    | 2 | INDEX FAST FULL SCAN | UI_PURGE_FT_PK | 23M| 136M| 13991 (2)| 00:02:48 |
    2.
    Execution Plan
    Plan hash value: 1974183109
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | | 2 (0)| 00:00:01 |
    | 1 | SORT AGGREGATE | | 1 | 6 | | |
    | 2 | INDEX FULL SCAN (MIN/MAX)| UI_PURGE_FT_PK | 23M| 136M| 2 (0)| 00:00:01 |
    | 3 | SORT AGGREGATE | | 1 | 6 | | |
    | 4 | INDEX FULL SCAN (MIN/MAX)| UI_PURGE_FT_PK | 23M| 136M| 2 (0)| 00:00:01 |
    | 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
    ---------------------------------------------------------------------------------------------

  • Find MAX date for Person XYZ , and also MIN date for same Person?

    List of dates in Column A , list of Persons in Column B.  My problem is that I have In C1 the formula which part of it is =SUMPRODUCT(MAX((B4:B200=A2)*A4:A200))) to find the MIN date for the person specified in cell A2, but this formula returns an error. Please help
    Many thanks
    NB: I use Numbers for the iPhone
           ans Icloude Numbers beta in the iMac 21.5

    Hi atapp,
    Here is my solution to your problem. The footer cell A11 is where you type your search. You could easily change this to C1 if tha makes more sense to you. Colomn C is where the action is and it could be hidden. The formulas in the two footer rows are =MAX(C) and =MIN(C) so even though they are in Column B they are looking at Column C.
    The formula in C2 is filled down.
    Give it a try.
    quinn

  • How to set min & max connections for  MSSQLconnection pool

    Hi,
    I want to set minconnection, maxconnection, idletimeout initial limit for the pool
    I have got a MSSQL database connection using following java code.
    // MSSQL DbConnection Code
    import java.sql.*;
    public class MsSqlDataSource
    public static void main(String arr[])
    Connection con = null;
    ResultSet rs = null;
    try{
    com.microsoft.sqlserver.jdbc.SQLServerDataSource ds = new com.microsoft.sqlserver.jdbc.SQLServerDataSource();
    ds.setServerName("10.50.50.51");
    ds.setPortNumber(1711);
    ds.setDatabaseName("test");
    ds.setUser("starhome");
    ds.setPassword("starhome");
    con = ds.getConnection();
    }catch(Exception e){}
    }In oracle i have passed min and max number of connection properties through setConnectionCacheProperties method.
    //Connection Pooling using Oracle Data Source:
    m_connSource = new OracleDataSource();
    m_connSource.setDriverType("thin");
    m_connSource.setServerName(m_host);
    m_connSource.setNetworkProtocol("tcp");
    m_connSource.setDatabaseName(m_db);
    m_connSource.setPortNumber(m_port);
    m_connSource.setUser(m_user);
    m_connSource.setPassword(m_password);
    // Enable caching. m_connSource.setConnectionCachingEnabled(true);
    java.util.Properties prop = new java.util.Properties();
    prop.setProperty("MinLimit", m_minConnections);
    prop.setProperty("MaxLimit", m_maxConnections);
    prop.setProperty("InitialLimit", m_initialConnections);
    prop.setProperty("InactivityTimeout", m_inactivityTimeout);
    prop.setProperty("AbandonedConnectionTimeout", m_abandonedTimeout);
    prop.setProperty("ConnectionWaitTimeout", m_connWaitTimeout);
    m_connSource.setConnectionCacheProperties(prop);I dont know how to pass min and max number of connection properties for SQLServerDataSource. Is there any method available to pass min and max number of connection properties for SQLServerDataSource.
    Iam using Tomcat. I found one way to set min and max connections for pool by doing changes in context.xml and web.xml using below url http://tomcat.apache.org/tomcat-4.1-doc/jndi-datasource-examples-howto.html
    I dont want to touch tomcat configuration files. I need to set connection pooling properties which is independent of application server.
    Please anybody give solution for this?
    Thanks,
    Prisha

    Hi,
    you need to define your database under the DB Admin tab. In the Schema objects node you'll find Sequence Implementations, and there you can definde min max values as well as caching and increments.
    Gerald

  • How to get min,max,avg time for query execution?

    Dear Friends,
    In AWR we are getting avg time taken to execute particular query, how can one get min,max time taken by query during number of executions.
    Thanks

    I would run the sql in a cursor for loop, to get a quite reasonable execution time without changing the actual execution plan:
    SQL> show user;
    USER is "HR"
    SQL> set timing on
    SQL> select count(*) from all_objects;
      COUNT(*)
         55565
    Elapsed: 00:00:03.91
    SQL> var p_sql varchar2(200)
    SQL> exec :p_sql := 'select * from all_objects'
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.00
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:03.53
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.75
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.73
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.66
    SQL> ---- alter system flush shared_pool;
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.80
    SQL> declare
      2  t1 timestamp := systimestamp;
      3  begin
      4    execute immediate 'begin for c in (' || :p_sql || ') loop null; end loop; end;';
      5    dbms_output.put_line('Elapsed: ' || (systimestamp - t1));
      6  end;
      7  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:02.64
    SQL>
    https://forums.oracle.com/thread/705536?start=15&tstart=0
    Regards
    Girish Sharma

  • How to set physical min/max values for a scale in xy graph?

    Hello,
    I have troubles with the way LabView handles physical units in xy graphs. In particular, I use a time scale for the x axis.
    The values are timestamps and have the unit [s]. Now I want to read write the min max values for this scale via
    property nodes. It seems that the properties for min max do not support the use of the unit I use for the data for
    that same axis. This is very inconvenient and I am not even sure which kind of data to use at all for this properties.
    Is it simply converting to/from [s] using the unit converter?
    (I am using LabView 7.1 for the programm in question).
    Thanks,
    Olaf

    Hi Olaf
    "It seems that the properties for min max do not support the use of the unit I use for the data for that same axis."  
    What are the units you are using? can you make it a littlebit clear.
    You can change the units also using Property node.
    Just check the attachment once. If that is what you are looking for, then the problem is solved.
    Regards
    Anil
    Message Edited by reddy on 05-23-2006 05:25 AM
    Message Edited by reddy on 05-23-2006 05:27 AM
    Attachments:
    X-Scale.jpg ‏8 KB

Maybe you are looking for

  • Table based on one data service but filtered by a second data service

    Hi, I'm fairly new to VC and have got comfortable with a few simple scenarios. However, I'm trying to apply some fundamental logic that must be possible and I'm guessing straight forward. I have a data service that contains document type master data

  • Odd problem with purchased music from ITMS

    Hi everyone. I purchased some songs on a friends computer via itunes with my account, but when bringing them over to my computer itunes asked me to authorize my computer. Any ideas? Thanks.

  • Keep library on external hard rive

    I want to add media files to Itunes so that they are availble to watch on apple tv but i want to leave the files on an external hardrive, not co[pied onto my mac. Is this possible?

  • I take pictures and when i try to bring them up big it show up blank

    i have an iphone 4s and when i take pictures it shows up in the camera roll, but when i try to bring up the pictures individually it is completely blank.

  • Web Service on ABAP

    Hi all, we face slight problems getting a web service run on WAS ABAP. The underlying FM as endpoint of the webservice has input and output parameter, is RFC-enabled I created the Web Service with the in SE80 integrated wizard, ABAP inside-out on an