Returning specific data on a query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Domino147
    New Member
    • Dec 2013
    • 2

    Returning specific data on a query

    I'm rusty on Access - have not used it since 2000. Currently have Access 2013.

    I would like to have the query return the first 3 months of data on oil production based on the completion date of the well.

    Code:
    Data fields:
    Completion Date         Production date:
    1/9/2009                1/1/2009
    1/9/2009                2/1/2009
    1/9/2009                3/1/2009
    1/9/2009                4/1/2009
    1/9/2009                1/1/2010
    Data expample above is for one well. I need the query to look at the completion date and return the first 3 production date data lines. Not all wells have a january completion date a sum type query won't work because wells that start in december would have production in jan-mar.

    Hope someone can help...I'm feeling very rusty..
    Last edited by zmbd; Dec 18 '13, 11:07 PM. Reason: [z{[Code/] formatted the posted data table}]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    that's all of the data?
    nothing to indicate the well such as:
    Code:
    Data fields:
    WellExample   Completion Date         Production date:
    1                1/9/2009                1/1/2009
    1                1/9/2009                2/1/2009
    1                1/9/2009                3/1/2009
    2                1/9/2009                4/1/2009
    2                1/9/2009                1/1/2010

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32655

      #3
      To help you, we'd need you to specify the problem more clearly. How is "first three months" defined?

      Comment

      • Domino147
        New Member
        • Dec 2013
        • 2

        #4
        Thank you for you help! The first 3 months is defined as the first 3 months after the completion date. So if a well is completed on 1/1/10 - I need the query to return the production data associated with 1/1/10, 2/1/10 and 3/1/10.

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          From the data you've provided, I really don't see any reasonable means to reliably return the results you desire.

          The best I can tell you is that you either have not provided enough of your dataset to for us to help and/or your database design has failed you in the most miserable way possible...

          So what I'm going to ask you to do is:
          1) Go back to your data. Almost anything in addition to what you have here might help.

          2) reveiw the following sites for how to design a RDMS.
          ---
          MS Access 2010 Tutorials
          Access Basics - By Crystal
          Micrsoft: Office2010 tutorials
          Microsoft: Getting started with Access 2010
          > Database Normalization and Table Structures.
          ---

          3) I am abhorent to provide the following:
          Based on the data you posted in #1

          Code:
          SELECT TOP 3 Table3.Completion , Table3.Production 
          FROM Table3
          WHERE ((([Production]>=[Completion]));
          This will return the first three records wherein the production date is greater than 1/9/2009 the 2/1/2009 - 4/1/2009 IT will not return the 1/1/2009 because that date is greater than the 1/9/2009
          FURTHERMORE: Even if you add 100 more records, it is only going to return 2/1/2009 - 4/1/2009

          You see, you've really not given us anything to really work with.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32655

            #6
            It may be as simple as :
            Code:
            SELECT [WellID]
                 , [Completion]
                 , [Production]
            FROM   [YourTable]
            WHERE  ([Production] Between [Completion] And DateAdd('m',3,[Completion]))

            Comment

            • zmbd
              Recognized Expert Moderator Expert
              • Mar 2012
              • 5501

              #7
              yes, but no [WellID] offered either in post 1 nor 4; however, I should have thought of the "Between"

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32655

                #8
                No need to beat yourself up about it Z. Sometimes it occurs to one and other times not. It often depends on how clearly the question is understood at the time.

                That, of course, depends on how it's written which, in turn, depends on the efforts of the poster, as well as - and here's the kicker - their experience. Many a well-intentioned member has done their best to make the question clearer, only to have exactly the reverse effect. Simply because they lack the experience to realise what things are most helpful and what things are not so much.

                For those of us wih more experience it seems just common sense, but often that's because we're so used to dealing with such situations.

                I suspect Domino felt he was simplifying the whole matter by leaving out any reference to the Well info in the explanation.

                Comment

                Working...