Results 1 to 2 of 2
  1. #1
    hellfire45 is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Mar 2015
    Posts
    24

    Some SQL beyond my abilities (please assist)

    So here is what I'm trying to do. I have one table with a bunch of Claim Numbers and each of these claim numbers may have a "judgment" date. Then I have another table that has SOME (maybe more or less) of the same claim numbers that have payments with payment amounts and payment dates. The first table has unique values in the claim number column but the second table has many entries with the same claim number as a claim can have many payments.

    I need to determine the sum total of a claims payments that occured before and after the judgment date. So If claim "A" has a judgment date of 1/1/2012 and has 10 payments, 3 before the judgment date totalling $150, then I need the "PRE-judgment total" column to say $150 and the rest "POST-JUDGMENT". I put some tables below that show Table 1, table 2, and the the desire result of the query.

    I think maybe a "correlation subquery" could be used to do this but I'm not confident enough to write it. I'll give a couple sample tables below. Can anybody please give me any guidance? These tables are very large. Hundreds of thousands of rows. I just need some SQL code for use in Microsoft Access that can make this possible. thank you so much!

    Table 1:
    Claim Number Judgment DAte
    104010 4/3/2012
    103050 2/2/2012
    103030 4/4/2012
    103031 8/8/2012


    Table2:
    Claim Number Payment Date Amount paid
    104010 2/2/2012 $10
    104010 3/2/2012 $10
    104010 4/6/2012 $10
    104010 5/6/2012 $10
    104010 6/6/2012 $30
    103050 1/1/2012 $30
    103050 1/15/2012 $30
    103050 2/1/2012 $30
    103050 2/15/2012 $30
    103030 2/2/2012 $30
    103030 3/2/2012 $15
    103030 4/2/2012 $15
    103030 5/2/2012 $15
    103030 6/2/2012 $15
    103031 6/6/2012 $15
    103031 7/6/2012 $20
    103031 8/6/2012 $20
    103031 9/6/2012 $20

    RESULT OF QUERY:
    Claim Number Pre Judgment Amt Post Judgment Amt Total Amt
    104010 $20 $50 $70
    103050 $90 $30 $120
    103030 $60 $30 $90
    103031 $55 $20 $75


  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    make a query in design view - with these 2 tables; join them by ClaimNumber and by date field; then you must go from design view to SQL view to see the text version of this query - find the join between the dates and manually alter the = symbol to be < symbol - save that query as PreQ

    repeat with a new query but this time change = to > and save that query as PostQ

    then you make a new query using PreQ as its record source with just 2 fields;option it to be an Aggregate Query with group on Claim and sum on Amount; save as SumPreQ
    repeat to make SumPostQ

    now make a new final query with SumPreQ and SumPostQ joined at the ClaimNumber - drag on your fields, and create the calculated field for the Total Amount.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. POS Abilities of Access?
    By conroy125 in forum Access
    Replies: 1
    Last Post: 04-20-2013, 09:05 AM
  2. Replies: 18
    Last Post: 10-17-2012, 07:38 AM
  3. Replies: 7
    Last Post: 08-03-2012, 12:08 PM
  4. Senseless, but please assist
    By djclntn in forum Queries
    Replies: 7
    Last Post: 11-21-2011, 07:02 PM
  5. **I need Help with EXCEL. Please Assist**
    By n in forum Import/Export Data
    Replies: 0
    Last Post: 06-23-2006, 10:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums