Fetch max datetime records based on cut off time

Hi,
I want to fetch max date timestamp value for each key value but i do have cut off time as 21:00:00, which means anything after this time will be considered as next date 00:00:00 time value. I have attached an example for the same and
result set which i want. Kindly provide a SQL query for fetching like this.
Note: I have to use in a SELECT statement and i should not use temp table or cte, because i have to use this piece of code in another program where i cannot use temp tables. :(
Thanks!
Input:
ID is my key value
Output:
Regards,
Fazlu

Hi,
It should be partition by ID column and we need to add 3 hours during ORDER BY clause, isn't it? 
select * from (select * , row_number() Partition by ID Order by Cast(dateadd(hour,3,[Date]) as date) DESC ) rnfrom yourtable) t WHERE rn=1
I will try the query in office tomorrow and let you know the status.
Thanks for the reply!!!
Regards,
Fazlu

Similar Messages

  • Plant cut off time to determine confirmed delivery date

    Hello Friends,
    Where do we maintain plant cut-off time for deliveries, while confirming delivery in sales documents, how system takes consideration of plant cut-off time?
    Can anybody help me ASAP?
    Thanks,
    Nilesh
    Edited by: Nilesh B on Jun 17, 2010 3:54 PM

    Hello Nilesh
    Apart from what usasapsd usasapsd  mentioned, you need to maintain working hours and assign them to the Factory calendar and/or Shipping Point.
    SPRO/IMG/Logistics Execution/Shipping/Basic Shipping Functions/Delivery Scheduling and Transportation Scheduling/Maintain Working Hours and Maintain Duration
    Hope this helps,

  • Order entry cut off time to avoide same day line itme confirmation

    Hello Friends,
    We have a very unique requirement as below u2013
    Business want SAP System to automatically determine the Order entry cut off time to avoid same day line item confirmation. I.e. If an order is entered after a specific time in a day (For example if order is entered after 2 PM local time) system should not confirm that order on the same day. In such cases system should confirm the schedule line for that line item on the next day.
    Requesting you kindly guide us if there is something we can do in SAP to achieve this.
    Thanks and Best Regards,
    Amol Wadekar.

    Hi,
    check the Rounding Work days in the shipping point customizing.
    "Rounding-up period for delivery scheduling (in days)
    The amount of time that the system automatically adds as a safety margin to the estimated time required for processing a delivery."
    Check also http://help.sap.com/saphelp_46c/helpdata/en/dd/5607e7545a11d1a7020000e829fd11/frameset.htm

  • Getting around my school's internet cut-off time

    I currently attend a prep school out on the east coast, and they have rules like a prison. One thing that really irritates me is that at 11:30 PM every night they shut off the internet. I can still see full bars in my airport but I cannot access any thing online, not even through iTunes store or Mail. Is there any way I can get around this and access the internet after it has been shut off?

    Probably not... It sounds like the school is cutting off access to external networks (i.e., the internet) at 11:30 (or, more likely, cutting off the access points in the dorms from external networks).
    It's not a hardware issue or something you can address in your computer -- it's a change in the network itself. I suppose you could break into your school's network operating center and change the settings, but that would be difficult, illegal, and probably get you expelled.
    Of course, you could get an EVDO-modem for your MBP (Verizon has one that uses the ExpressCard slot). Service is about $80/month, and the speeds are not quite broadband, but if you really need to get on the network it might be worth looking into.
    Or you could just go to bed at 11:30...

  • Online order cut off times for next day delivery

    what is the latest time I can order off your web site for next day delivery?thanks

    For all waiting on your preorders- I preordered mine Sept. 5th about 5 hours after the announcement (engraved, standard shipping). It was shipped Sept. 19th and was delivered to my house at 10am today (Sept. 20th), despite having an estimated delivery date of Sept. 21st. As noted in another post, they seem to be coming out of Kunshan, China and then Shanghai and Anchorage, Alaska. Mine might have arrived a day early because Indianapolis is a major FedEx hub and there is a direct flight from Anchorage to Indy. Suspect many will get their Touch models today and tomorrow.

  • Fetching 3 laks records from the database

    Hi All,
    I have a requirement that if we are fetchin 3 lakks records from the database, can we fetch the records in a single span of time ,if yes then how?
    If no, then we have to fetch the recods multiple times but since for the first time it is fetching 1 lakh records and for the next time how the bpel engine know that it has to fetch 1000001 record.
    Can anybody came this type of scenario. Please guide me on this.
    Regards,
    Ch

    There are some options given here @ http://myexperienceswithsoa.blogspot.com/2010/06/db-adapter-polling-tricks.html
    Check them out.
    But if you reading so much of data at once, you better have the necessary infrastructure to handle the load like memory, jvm tuning, etc ...
    If there is a limitation, you will need to assess your polling record count to be may 10K or so to strike a balance on the performance.
    Hope this helps.
    Thanks,
    Patrick

  • ITunes cuts off some of my songs at exactly 3 minutes 6 seconds.

    I have a MacBook Pro running Mountain Lion with up to date updates.  Strangely, the songs which used to play right through, now stop at exactly 3 minutes and 6 seconds.  The songs also cut off when I play then through my iPhone 4 after sycing.
    When I play the songs through VLC Media Player via Finder, they play right through perfectly.
    I wonder whether this is a fault that's come about through one of the Mountain Lion updates recently. 
    I've seen a lot of posts with people's songs being cut off short but none make reference to the exact cut off time of 3 minutes, 6 seconds.
    I have gone into Get Info for the songs in iTunes and specified the ending time of each song to the song's actual length but they still stop at 3 minutes 6 seconds.  Most of my songs play through fine - it's just a bizarre handful.
    I hope there's a workaround and would appreciate a solution.
    thanks for your time.

    Hello arcuspilot,
    I would be concerned too if some of my songs were not playing all the way through in iTunes.  Thank you for all the details you provided.  You have gone through some really good troubleshooting steps already. 
    The next thing I recommend is checking to see if any third-party plug-ins could be causing the problem.  You can find the steps to do that in this article:
    iTunes: Troubleshooting issues with third-party iTunes plug-ins
    http://support.apple.com/kb/TS3430
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • Query to get the a/r receivables based on a cut-off date

    I would like to ask assistance on how to create a query to display a/r receivables using a cut-off date. Example, today is 05/07/2014, I want to display  a/r posted from Jan. 1 2013 up to Dec. 31, 2013 that are still unpaid  as of April 30, 2014.

    Hi,
    Try this:
    eclare @Cust as nvarchar(20)
    Declare @FromDate Datetime
    Declare @ToDate Datetime
    declare @Group as nvarchar(20)
    set @cust = (select max(t0.cardcode) from OINV t0 where t0.cardcode = '[%0]')
    Set @FromDate = (Select min(t0.Docdate) from dbo.OINV t0 where t0.Docdate >='[%1]')
    Set @ToDate = (Select max(t0.Docdate) from dbo.OINV t0 where t0.Docdate <='[%2]')
    set @group = (select max(t2.groupname) from OCRG t2 where t2.groupname = '[%3]')
    SELECT [CustName] as CustName, [G] as CustGroup,[1] as Jan,[2] as Feb,[3] as Mar,[4] as April,[5] as May,[6] as June,[7] as July,[8] as Aug,[9] as Sept,[10] as Oct,[11] as Nov,[12] as Dec
    from
    (SELECT T0.[CardName] as CustName, sum(T0.[DocTotal]) as Total, datepart(mm,T0.[DocDate]) as week, t2.groupname as G  FROM OINV T0   left JOIN OCRD T1 ON T0.CardCode = T1.CardCode left JOIN OCRG T2 ON T1.GroupCode = T2.GroupCode   WHERE year(T0.[DocDate]) = 2013 and T0.[CardCode] = @Cust and  T0.[DocStatus]  ='o' and T0.[DocDate] between @fromdate and @todate and t2.groupname = @group GROUP BY T0.[CardName],T0.[DocDate],t2.groupname
    union all
    (SELECT T0.[CardName] as CustName, -sum(T0.[DocTotal]) as Total, datepart(mm,T0.[DocDate]) as week,t2.groupname as G  from ORIN T0  left JOIN OCRD T1 ON T0.CardCode = T1.CardCode left JOIN OCRG T2 ON T1.GroupCode = T2.GroupCode   WHERE year(T0.[DocDate]) = 2013 and T0.[CardCode] = @Cust and  T0.[DocStatus]  ='o' and T0.[DocDate] between @fromdate and @todate and t2.groupname = @group  GROUP BY T0.[CardName],T0.[DocDate],t2.groupname )) S
    Pivot
    (sum(S.total) For WEEK IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
    Thanks & Regards,
    Nagarajan

  • SQL Query to retrieve the All records based on the Max Dates.

    Hello all,
    I am trying to retrieve the newest record based on the date field (  nextDate  ).
    Currently there are only 4 records in the MC_Maintenance table and two in the Machine table.
    Machine table
    MC_id             EquipID          
    1                      0227
    MC_id             EquipID
    2                     0228
    MC_Maintenance table
    Maint_id           MC_id             Next_maint                  
    1                      2                      08/25/2010     
    2                      2                      07/01/2010
    3                      1                      06/11/2010
    4                      1                      07/11/2010
    What I  am trying to accomplish is,
    list the two machines from the Machine table with the MAX(Next_maint) controlling the MC_Maintenance output list
    These are the records that I would like to Display.
    Maint_id           MC_id             Next_maint                  
    1                      2                      08/25/2010
    4                      1                      07/11/2010                 
    Below is the SQL Query
    SELECT
           MC.MC_ID as ID,
            MC.complete_Date as completed,
            MC.next_maint as nextDate,
            MC.maint_notes as Notes,
            MC.facility as Facility,
            M.EquipId,
            M.name as name,
            M.SerialNumber as SN,
            M.dept as dept,
            M.Freq as freq
            From  MC_Maintenance MC, Machine M
            where  MC.MC_ID =  M.MC_ID
    '           USING MAX(nextDate )
    Any ideas would help.
    TJ

    I would have thought that was a simple group by problem?
    SELECT M.EquipID, MC.MC_ID, Max(MC.next_maint)
    FROM MC_Maintenance MC INNER JOIN Machine M ON MC.MC_ID = M.MC_ID
    GROUP BY M.EquipID, MC.MC_ID

  • Fetch the records based on number

    Hi experts,
        I have a req like if user give input as 5..it should fetch 5 records from database.
    for example database values are
    SERNR                MATNR
    101                                              A
    102                                              A
    103                                              A
    104                                              A
    105                                              A
    106                                              A
    107                                              A
    If user gives the input as 5 it should fetch 5 records like 101 to 105....Can any body plz help me how to write select query for this..
    Thanks in advance,
    Veena.
    Edited by: s veena on Jan 18, 2011 5:52 AM

    Hi Veena,
    You can use UPTO in your select query. For example
    SELECT MATNR FROM MARA INTO TABLE IT_MATNR UPTO P_NUMBER ROWS.
    "Here P_NUMBER is the Selection Screen Parameter
    It will fetch records based on the number in the parameter.
    Thanks & Regards,
    Faheem.

  • How to select records based on Max/Min on different columns and group by

    I have a table with 5 columns(a,b,c,d,e), i need to select records based on MAX(c),Max(D) and Min(e) group by a,b. i am trying using : select max(c),max(d),min(e) from table group by a,b. this is not working. its giving me 1 6 1
    a b c d e
    1 1 1 2 1
    1 1 1 6 4
    1 1 1 6 3
    when i group by a,b i am expecting the record 1 6 3
    Please help me with this.. Thanks in advance....

    Hi,
    Welcome to the forum!
    962163 wrote:
    I have a table with 5 columns(a,b,c,d,e), i need to select records based on MAX(c),Max(D) and Min(e) group by a,b. i am trying using : select max(c),max(d),min(e) from table group by a,b. this is not working. its giving me 1 6 1
    a b c d e
    1 1 1 2 1
    1 1 1 6 4
    1 1 1 6 3
    when i group by a,b i am expecting the record 1 6 3It looks to me like "1 6 1" is the correct answer. You're asking for the lowest value of e, and 1 is lower than 3.
    Maybe you don't want MIN (e). Explain why you want 3 (that is, how you decided that 3 is the correct value for the last column) and someone will help you code it.
    Edited by: Frank Kulash on Sep 28, 2012 6:17 PM
    Whenever you have a problem, you should psot CREATE TABLE and INSERT statements for your sample data. That way, the people who want to help you can re-create the problem and test their ideas. It often helps to clarify the problem, too. since this is your first message, I'll do it for you:
    CREATE TABLE     table_x
    (       a     NUMBER
    ,     b     NUMBER
    ,     c     NUMBER
    ,     d     NUMBER
    ,     e     NUMBER
    INSERT INTO table_x (a, b, c, d, e) VALUES (1, 1, 1, 2, 1);
    INSERT INTO table_x (a, b, c, d, e) VALUES (1, 1, 1, 6, 4);
    INSERT INTO table_x (a, b, c, d, e) VALUES (1, 1, 1, 6, 3);
    COMMIT;

  • Win7, DW CS6, Find and Replace, Problem: The "Done or Found" message is cut off based on your SEARCH dropdown choice.

    The Find and Replace "Done or Found" message is partially cut off for "Search" dropdown choices "Source Code, Text, Text (Advanced), but not for "Specific Tag". It appears to be a programming bug sizing the "Find" and "Replace" text boxes too big for the "find and Replace" window. Has anyone else encountered this problem.

    Excuse me for resurrecting this, but I have been living with this same issue, and many more issues (I won't list them here), since migrating to CS5 (understood this thread is for CS6. However, my post is relevant none the less). If anyone has the fix I would love to know what they found. But sadly, I doubt there is one.
    My system and display settings are also Win7 at 100% display. When doing a Find and Replace I can barely see what the results are for how many occurrences in the find window because the bottom is cutting off half of the text, just like the OP screen shot above. If the results reads "Done. 2 items found" it can easily be mistaken for "Done. 3 items found" if I don't study it carefully because of the bottom half of the "2" is cut off.
    I don't want to rant here, but I will a little which I'll confess is the real purpose of my post. I am so disappointed in Adobe for so many different bugs in their software suite which they choose not to address, or even acknowledge as existing. I've had their tech support on the phone while they were recording my screen as I recreated issues for them, they never got back to me on any of them. I just got lip service how their engineers are looking into it and they'll get back to me. This of course was when CS5 still had free support under warranty.
    At this point I'm numb to it all and I'm stuck using their software because I'm used to it, which ultimately is their goal anyway I'm sure. You win Adobe.
    BTW...if anyone replies, please do not suggest the basic troubleshooting steps. All of the issues I've had exists after multiple re-installs on formatted hard drives and on both of my PCs made by two different manufacturers with different hardware specs (both exceeded min hardware requirements). Not to mention been through various techniques while on the phone with them..
    Ahh... I feel better now.

  • Keynote 6.5 audio cuts off in the middle of a recording

    I am trying to record a Keynote presentation with narrative then convert it to a movie and post it to YouTube.  I created and saved the presentation, verified the recording then exported it to Quicktime.  From there, I loaded it up to YouTube but discovered that the audio was cut off within the first minute or two.  When I went back to the original recording, it appears that the audio was cut off when it was being converted to a movie.  Is this a known bug or am I doing something wrong?  Any fixes out there?  Thank you.

    One example of an affected clip:
    Source is from a Panasonic HD camera--so transferred to FC from a P2 card
    Item properties:
    817.5 MB
    960x720
    DVCPRO HD 720p60, Interger (little Endian), Timecode
    Hey--could this be caused by the frame rate of the sequence? I just noticed that the sequence these affected clips are in is 60fps, and my video clips are 23.98fps. So--I copied and pasted my clips into a new 23.98 sequence and the issue has gone away. Huh. Oops... Not enough coffee this morning.
    Thanks for trying to help out--sorry to have answered my own question (duh).
    Message was edited by: Coyotegyrl

  • Early cut off when recording on extra channels

    I have noticed that when recording on the extra BT channels eg Sony etc that they cut off the recording in the closing minutes of the programme. Also they may start slightly late which means missing one end of the programme. Why is this?

    According to Youview experts: 
    The (Freeview) EPG is managed and broadcast by Digital UK who are licensed by Ofcom to provide this service.
    Providing EPG data 
    The EPG/schedule data is collated and a complete set of data to be carried on each of the multiplexes on the platform is published. The result is that whatever multiplex a viewer is watching they always have the latest set of schedules available via the EPG.
    Digital UK handles the full suite of event descriptors listed in D-Book from basic details such as the title, synopsis and TX time of each event, to the data for clash management and series recordings for Freeview+ and Freeview+HD products.
    Standard offering includes real-time response to schedule data delivery and web-portal for monitoring. Options in terms of connectivity to the collator and enhanced triggering of now/next data are also available.
    The EPG can be updated several times a day or more if necessary. If the broadcaster has opted for enhanced triggering (and therefore is permanently connected to Digital UK’s systems) these triggers are updated and broadcast dynamically.
    It is not mandatory for broadcasters to provide NOW/NEXT info. If the data isn’t provided then the EPG scheduled time triggers NOW/NEXT.
    However ...according to Youview personal
    All UK digital terrestrial (aka Freeview) broadcasters supply now and next information using a system called "EIT PF" ("Event Information Table - Present Following"). It's not optional.
    And all recordings on YouView are triggered from that data - there's only one system as far as the box is concerned. However, the accuracy of those signals varies between broadcasters (acknowledged by YouView and the broadcasters)
    The questions for BT are ...(1) .do all the extra channels that BT transmit use the EIT PF system ?
    -(2) do BT's own channels use the EIT PF system ?
    - (3) do BT Sport channels utilize enhanced triggering of now/next data?
    It has proved very difficult to get a precise answer to such questions ?

  • How to fetch the data records in summary format based on previous day

    drop table T1;
    create table T1(Class, Fees_Collected, Submit_Date) as select
    'MBA', 100000, '7/30/2012' from dual union all select
    'Btech', 20000, '7/10/2012' from DUAL union all select
    'MBA', 45000, '8/1/2012' from dual union all select
    'Btech', 55550, '7/31/2012' from DUAL union all select
    'BBA', 250660, '7/30/2012' from dual union all select
    'MBBS', 44556000, '7/31/2012' from DUAL union all select
    'BDS', 420050, '8/1/2012' from DUAL union all select
    'BBA', 30450, '7/30/2012' from DUAL union all select
    'MBBS', 120450, '7/31/2012' from DUAL union all select
    'BDS', 45950, '7/30/2012' from DUAL union all select
    'MBA', 252450, '8/1/2012' from DUAL;My requirment is to fetch the records based on summary format to display the data with following columns -
    Class |Prev Day Traded Value |Prev Day % of Total |Prev Day % MBA
    Note - Previous Day definiton (Buisness Day) = calendar days - (weekends + US Holidays)
    Kindly help me, as i want to keep it customized so that without specifying the hard coded dates ( Previous Day) it runs through and provide me the resultset....
    All of your help and time is highly appericated.

    You mean business days I guess ?
    I use a function (I had to write it myself) <tt><b> next_business_day(p_start_date in date,p_days_count in number) return date </b></tt>
    where I loop forward/backward from p_start_date according to the sign of p_days_count the required number of steps skipping weekends and holidays as the absolute value of p_days_count is mostly under 30 for the rest (at least around here) Oracle's <tt><b> add_months </b></tt> gets it done.
    Regards
    Etbin
    Edited by: Etbin on 6.8.2012 17:55
    Year till date: <tt><b> your_date between trunc(sysdate,'year') and sysdate </b></tt> is it ? http://en.wikipedia.org/wiki/Year-to-date ?
    Edited by: Etbin on 6.8.2012 18:27
    NOT TESTED!
    function next_business_date(p_start_date in date,p_count_days in number) return date is
      steps  number := abs(p_count_days);
      retval date := p_start_date;
    begin
      if p_start_date is null or p_count_days is null then
        return to_date(null);
      end if;
      while steps > 0
      loop
    /* skipping weekends and (yet to be implemented) holidays */
        while to_char(retval,'dy') in ('sat','sun') /* or is_holiday(retval) */
        loop
          retval = retval + sign(p_count_days);
        end loop;
    /* retval contains a business day now */
        retval = retval + sign(p_count_days);
        step := step - 1;
      end_loop
      return retval;
    end;

Maybe you are looking for