How to get the first and the last record of every month within a time range in sql

I am trying to get the first record and the last record of each and every month in a given date range using sql. I have a sample code
where i have just selected everything within the date range now i have to extract the first and the last records of each and every month.
SELECT PurOrderNum,
OrderDate
FROM Purchasing.PurOrder
WHERE OrderDate >= '2013-02-28'
AND OrderDate <= '2014-12-29'

SELECT PurOrderNum,
OrderDate
FROM
SELECT PurOrderNum,
OrderDate,
MAX(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MaxDate,
MIN(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MinDate
FROM Purchasing.PurOrder
WHERE OrderDate >= '2013-02-28'
AND OrderDate <= '2014-12-29'
)t
WHERE OrderDate = MaxDate
OR OrderDate = MinDate
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page

Similar Messages

  • Get the first and the last date of a week

    Hi all
    I need to get the first and the last date of a specific week.
    I need a function that returns two date passing it just one date.
    The function has to calculate the first and the last date of the week of the argument date.
    hope to be clear
    regards

    goiters,
    I need to get the first and the last date of a specific week.Yup, and what's the first day of the week in your part of the world, is it Sunday or Monday?
    I need a function that returns two date passing it just one date.No you don't, just add 7 days to the start of the week.
    hope to be clearWell, you can hope.
    Keith.
    Message was edited by: corlettk - now I hope to clear ;-)

  • How to view the first and the last frame of a clip or a selected range in the time line?

    How to view the first and the last frame of a clip directly or in a selected range in the time line ? Up arrow and down arrow keys changes only between the first frame of the consecutive clips. Even ; and ' does the same. I mean what is the shortcut keys for first to last and last to first frame of a clip? Help please.

    SELECT PurOrderNum,
    OrderDate
    FROM
    SELECT PurOrderNum,
    OrderDate,
    MAX(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MaxDate,
    MIN(OrderDate) OVER (PARTITION BY DATEDIFF(mm,0,OrderDate)) AS MinDate
    FROM Purchasing.PurOrder
    WHERE OrderDate >= '2013-02-28'
    AND OrderDate <= '2014-12-29'
    )t
    WHERE OrderDate = MaxDate
    OR OrderDate = MinDate
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How can I distinguish between the first and the rest in Smartforms??

    I have made an Invoice in Smartform. I have to take three copies of that. In the first copy it will be printed "ORGINAL INVOICE" and in the next copies it will print "Duplicate copy".  How can I distinguish between the first and the rest in Smartforms??
    Regards,
    Subhasish

    >
    Subhasish Ganguly wrote:
    > I have made an Invoice in Smartform. I have to take three copies of that. In the first copy it will be printed "ORGINAL INVOICE" and in the next copies it will print "Duplicate copy".  How can I distinguish between the first and the rest in Smartforms??
    Hello Vamshi,
    As per the OP's requirement he has to print 3 copies of the invoice. Which according to my understanding should be printed at the same time ? May be i am wrong in interpreting this.
    You must be knowing you can control the print params of the SmartForms in CONTROL_PARAMETERS where you set the NO_DIALOG & in the OUTPUT_OPTIONS pass the number of copies.
    I think the solution you have proposed the "Original Copy" will be printed only once. (Correct me if i am wrong)
    Every time the user prints the invoice again he will be getting a "Duplicate Copy". If this is what the OP wants the logic is perfect
    Cheers,
    SUhas

  • My iPhone rejects my passcode when I enter it the first and the second time

    My iPhone rejects my passcode when I enter it the first and the second time. Why?

    Is it random? Does it occasionally accept the passcode, or does the passcode seem to be changed?
    See Kappy's list on how to deal with passcode problems:
    Re: Passcode being rejected   https://discussions.apple.com/message/23376400#23376400

  • Getting the first and the last record with analytics

    I have a table called horario (time) which has the following columns: card_number,
    card_holder_name, card_reader_location and time. I came up with the following sql
    statement that gives me the current row and the next row so I can subtract one from
    the other and see how much time elapsed between them. As you can see below:
    SELECT *
    FROM   (SELECT card_number,
                   reader card_reader_location,
                   hora TIME,
                   lead(reader) over(PARTITION BY card_number ORDER BY hora) next_card_reader_location,
                   lead(hora) over(PARTITION BY card_number ORDER BY hora) next_time_action
            FROM   horario
            WHERE  card_number = '26965'
            AND    to_char(hora, 'DD-MON-YYYY') =
                   to_date('03-JAN-2006', 'DD-MON-YYYY')
            GROUP  BY card_number,
                      reader,
                      hora)
    CARD_NUMBER               CARD_READER_LOCATION                               TIME                 NEXT_CARD_READER_LOCATION                          NEXT_TIME_ACTION                                                                                                                                      
    26965                     BASEMENT DOOR READER  IN                           03-JAN-2006 07:26:00 BASEMENT DOOR READER  OUT                          03-JAN-2006 14:44:00                                                                                                                                  
    26965                     BASEMENT DOOR READER  OUT                          03-JAN-2006 14:44:00 BASEMENT DOOR READER  IN                           03-JAN-2006 14:45:00                                                                                                                                  
    26965                     BASEMENT DOOR READER  IN                           03-JAN-2006 14:45:00 BASEMENT DOOR READER  OUT                          03-JAN-2006 16:07:00                                                                                                                                  
    26965                     BASEMENT DOOR READER  OUT                          03-JAN-2006 16:07:00                                                                                                                                                                                                           Now I need to come up with a sql query that will subtract the time field of the very
    last row (16:07:00) and the time field of the very first row (07:26:00) so I know how
    many hours were worked on that specific date. Can I do that using analytics ? If so,
    how ?
    thanks !
    gleisson henrique

    In a way you can get those min/max dates in the same row and subract them in the outer select just like this
    SELECT *
    FROM (SELECT card_number,
    reader card_reader_location,
    hora TIME,
    lead(reader) over(PARTITION BY card_number ORDER BY hora) next_card_reader_location,
    lead(hora) over(PARTITION BY card_number ORDER BY hora) next_time_action
    max(hora) over(PARTITION BY card_number) max_hora,
    min(hora) over(PARTITION BY card_number) min_hora
    FROM horario
    WHERE card_number = '26965'
    AND to_char(hora, 'DD-MON-YYYY') =
    to_date('03-JAN-2006', 'DD-MON-YYYY')
    GROUP BY card_number,
    reader,
    hora)

  • How to find FIRST and the LAST date of the month.

    Hello,
    I want to find the first and the last date of the current month through query. How is it possible please help.
    For example if the current month is july. The first date should be 01-JUL-2006 and the last date would be 31-JUL-2006.
    Please help me.
    Regards,
    Imran Baig

    Like this?
    SQL> select trunc(sysdate,'MM') "First_Day",
      2        last_day(sysdate) "Last_Day" from dual;
    First_Day Last_Day
    01-JUL-06 31-JUL-06
    SQL> select trunc(to_date('10-FEB-04'),'MM' ) "First_Day",
      2       last_day(to_date('10-FEB-04')) "Last_Day" from dual;
    First_Day Last_Day
    01-FEB-04 29-FEB-04

  • When was the first and last login of a db user

    Hi @ all,
    I'm trying to find out the first and the last login of a special db user at an Oracle 10g (10.2.0.1.0) Instance.
    How can I do that?
    Thanks and best regards,
    David

    What Nicholas said is true, but depending what you are looking for, you may also search/review audit files created by everytime a sysdba or sysoper session was created by looking in your audit directory.
    From within sqlplus, "show parameter audit"
    Then, go to that directory and you will see hundreds/thousands of audit files for each time a sysdba or sysoper session was started.
    Within those logs are entries such as:
    Tue Mar 12 16:00:00 2013 -04:00
    LENGTH : '155'
    ACTION :[7] 'CONNECT'
    DATABASE USER:[1] '/'
    PRIVILEGE :[6] 'SYSDBA' <=========== sysdba or sysoper (I believe this is all that is captured.)
    CLIENT USER:[6] 'oracle' <=========== shows the OS user that connected to the database
    CLIENT TERMINAL:[0] ''
    STATUS:[1] '0'
    DBID:[10] '1321231341'

  • How to get the first and last record

    Hai All
    I have table called T1 and there are more than 8 lakhs records and i have a column called Timestamp so i need to get the first record value and time stampvalue and last record and time stamp value so that i can conclude that For Example
    form 13 june to 15 june data are here
    Kind Regards
    SrikkanthM

    Something like this can also indicate the first and last rows as you query...
    SQL> select empno, ename, hiredate
      2        ,case row_number() over (order by hiredate)
      3           when 1 then 'First Row'
      4           when count(*) over () then 'Last Row'
      5         end as flag
      6  from emp;
         EMPNO ENAME      HIREDATE            FLAG
          7369 SMITH      17/12/1980 00:00:00 First Row
          7499 ALLEN      20/02/1981 00:00:00
          7521 WARD       22/02/1981 00:00:00
          7566 JONES      02/04/1981 00:00:00
          7698 BLAKE      01/05/1981 00:00:00
          7782 CLARK      09/06/1981 00:00:00
          7844 TURNER     08/09/1981 00:00:00
          7654 MARTIN     28/09/1981 00:00:00
          7839 KING       17/11/1981 00:00:00
          7900 JAMES      03/12/1981 00:00:00
          7902 FORD       03/12/1981 00:00:00
          7934 MILLER     23/01/1982 00:00:00
          7788 SCOTT      19/04/1987 00:00:00
          7876 ADAMS      23/05/1987 00:00:00 Last Row
    14 rows selected.
    SQL>

  • How do I easily select a group of emails in Apple Mail if I want to delete them? In other words, how do I select the first and last message and delete everything in between?

    How do I easily select a group of emails in Apple Mail if I want to delete them? In other words, what do I select if I mark the first and last email to delete everything in between? Thanks.

    I have this same issue. I have over 100 email addresses that I need to add to a group. The issue is not making the group, it's getting the email addresses from Mail to Contacts.
    Dragging the email addresses does nothing. You can copy the addresses, but there's nowhere to put them. You can make a VCF for an email address, but then you have to find all of them to add them to the group. How do you automate this?!
    I'm astounded that there's so little support for such a common issue for which people have been asking for years.

  • I ended up having two id's, one being my original when first getting into itunes and the other came when I opened a me account.  I have purchases under the original id.  How do I merge the old account into the new account

    I ended up having two id's, one being my original when first getting into itunes and the other came when I opened a me account.  I have purchases under the original id.  How do I merge the old account into the new account

    Sorry, but it is not possible to merge two Apple IDs/iTunes Store accounts.
    Regards.

  • How can I display the first and last name using a paramater as employee ID?

    Hi SAP,
    I have a parameter that is called {? Employee ID}.   What I want to do is display the first and last name based on the employee ID value entered in {? Employee ID} in the page header of the report.  Right now, when I put the following formula in the page header only some pages get the right result while other pages dont....
    if table.employeeid = {? Employee ID} then
    table.firstname" "table.lastname
    It appears as though if the first record in the details section on the beginning of each page happens to be the employee under {? Employee ID} then it prints it correctly, if it isn't I get a null value in the page header.
    Anyone have any ideas?
    Z

    Hi Try this,
    Whileprintingrecords;
    if ={?EmpID} then
    Also check the option "Default values for null" in the formula editor.
    Regards,
    Vinay

  • How to get the first and second quarter from CRT

    Dear Freinds,
                    I have one scenario , the Functional SPEC says Read the payroll results and from the CRT  get all the 4 quaters
    for the wage type /5UH  and sum them and then pass on the to field in the main strucutre.
    Iam using the FM HR_GET_PAYROLL_RESULTS
      CALL FUNCTION 'HR_GET_PAYROLL_RESULTS'
        EXPORTING
          pernr                         = fp_v_pernr
          permo                         = fp_v_permo
          pabrj                         = fp_v_pabrj
          pabrp                         = fp_v_pabrp
          actual                        = 'A'
        TABLES
          result_tab                    = i_payresult
        EXCEPTIONS
          no_results                    = 1
          error_in_currency_conversion  = 2
          t500l_entry_not_found         = 3
          period_mismatch_error         = 4
          t549q_entry_not_found         = 5
          internal_error                = 6
          wrong_structure_of_result_tab = 7
          OTHERS                        = 8.
    Iam collecting all the Actual Result (current result) values
    on the selection screen iam passing for month april (04 2008)
    so this falls in the second quater .
    the internal table   i_payresult is picking up only the second quater (01-04-2008 to 30/04/2008 )  ,but since on the selection screen iam pasing as other period (04 2008) the internal table  i_payresult  returing from the FM  (HR_GET_PAYROLL_RESULTS) only   picks the second quater,
    could any one let meknow how i can pick up the first quarter as well and add the first and second quater to mee the requirement .
    Please help me in this regard
    Thanks & regards
    maduri

    Hi Manoj,
                 Thank you for giving me idea for going further  regarding this problem , so my final question for this is
    as per FS they said they are going to enter the payroll
    area and the other selection as 04 2008 
    In order to achieve the first quarter , because 04 2008 means they are going to enter for the second quarter , the payroll results will come only for second quarter and not for the first quater , if they want to sum all the two quarters then they shouldnt pass on the selection screen   the dates as 04 2008, instead they has to pas
    01 01 2008 to 30 06 2008 , as there is no point in they passing as 04 2008 as we are going to consider from 01 2008 to 062008 .   Please correst me if am correct regarding the dates passing on teh selection screen
    or if the user enters on theslection screen still enter 04 2008 and will be  able to acheive the first quarter ??
    Please answer me this point before i can change the logic of the code and tell to my FO regarding this point.
    thanks & regards
    Madhuri

  • How to show the First and Last name of the user instead of user name

    Gurus,
    We have the full email id of the user as the portal user name. Right now we are using the "Item Attributes - Current User" to show the user name. We don't want to show this anymore. We would like to show the First and Last name of the user on the Portal page. How can i do this. Please post a reply if you have some idea about it.
    Thanks
    Raj
    ---------

    I believe this is possible using the security APIs. See http://portalstudio.oracle.com/pls/ops/docs/FOLDER/COMMUNITY/PDK/PLSQL/DOC/PLDOC_9026/INDEX.HTML and look for person_info (Returns user information, given a user name)
    under wwsec_api
    Suggest posting any follow-up questions to the Security forum - http://forums.oracle.com/forums/forum.jsp?forum=6

  • My computer was refreshed and the technician did not deactive the CS3 license first and the drive has been wiped. I have my serial number, how can I get it activated?

    My computer was refreshed and the technician did not deactive the CS3 license first and the drive has been wiped. I have my serial number, how can I get it activated?

    Hi pipper88,
    You can reinstall CS3 and enter the serial number to activate the software.
    Regards,
    Rave

Maybe you are looking for

  • Creation of IBase for Production data or sales order  in R/3

    Hi, My client is a locomotive manufacturing Company, They want to track the failure of parts in the locomotive  and any changes made in the locomotive during service. Kindly explain your thought on the following: 1. Here Each locomotive will have an

  • How do I quickly select a series of events in Yosemite's Calendar App?

    I know users can still hold down the shift key and select multiple events (One at a time). However, the last version of Calendar allowed users to select a series of events (such as 20) all at once by clicking on the first and last event while holding

  • Issue with Exclude Char Values in BI 7.0 report

    Hello, I have a report where its displays all Materials of Milk and Non Milk products. So my requirement is to see both Milk and Non Milk products separately in report. Inorder to see Milk products I can use selct filter value option where I can give

  • Macbook Pro recognises webcam but gives no video

    I recently started to use a usb camera (Microsoft LifeCam Cinema) to have meetings with teams abroad. It was possible on two occassions to get video from the webcam. However, this morning plugging the webcam in caused the Macbook Pro to reboot. This

  • Need Acrobat Pro 9 Volume License installer

    I just finished a very frustrating chat session with the Adobe support people who notified me that they could not help me in any way when it came to aquiring the Acrobat Pro 9 installer from the Volume Licensing Center. I have a valid serial and need