Results 1 to 3 of 3
  1. #1
    Fivehole91 is offline Novice
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    2

    Need help correcting record count

    i have seen multiple examples of advice on this particular subject, but i dont understand SQL, and therefore don't understand what needs to be done in order to add the "distinct" piece to my query. i only deal with access in its basic form, but here is the SQL version of the query i need help with. if i group by, i get a certain number of records, which is correct, but when i count the loan number field, the result produces additional records. Please help me understand why, if possible, and most importantly, what changes should be made in order to eliminate the erroneous count. thanks in advance!!

    SELECT DISTINCT Count(tblSurveys.LoanNum) AS CountOfLoanNum, tblSurveys.AU
    FROM tblSurveys LEFT JOIN tblEmployee ON tblSurveys.UnderwriterID = tblEmployee.ID
    WHERE (((tblSurveys.MonthReported) Between [Forms]![Data Input]![Start Date1] And ([Forms]![Data Input]![End Date1]+1)))


    GROUP BY tblSurveys.AU;

  2. #2
    TheShabz is offline Court Jester
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    1,368
    If you have an AU of x and LoanNums 1, 1, 1, 3, 5, are you looking for the count to show up as 5 or 3? It looks like from your description that you want it to show up as 3, but I just want to make sure. I dont think using DISTINCT will work in that case. You will need a subquery that will first get you the distinct LoanNums per AU.
    First create the following query and call it whatever you want, for the sake of the thread, "qryStep1":
    Code:
    SELECT tblSurveys.AU, tblSurveys.LoanNum
    FROM tblSurveys LEFT JOIN tblEmployee ON tblSurveys.UnderwriterID = tblEmployee.ID
    WHERE (((tblSurveys.MonthReported) Between [Forms]![Data Input]![Start Date1] And ([Forms]![Data Input]![End Date1]+1)))
    GROUP BY
    tblSurveys.AU, tblSurveys.LoanNum
    Then the following query
    Code:
    SELECT Count(qryStep1.LoanNum) AS CountOfLoanNum, qryStep1.AU
    FROM qryStep1
    GROUP BY qryStep1.AU

  3. #3
    Fivehole91 is offline Novice
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    2
    thanks very much for your reply! that did the trick...

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

Similar Threads

  1. Help for correcting Before Update
    By Pragmatic in forum Forms
    Replies: 11
    Last Post: 12-28-2011, 11:59 AM
  2. correcting typographical errors
    By aflashman in forum Access
    Replies: 1
    Last Post: 07-31-2011, 03:22 PM
  3. Record Count within a Report
    By BLD21 in forum Reports
    Replies: 1
    Last Post: 04-06-2011, 10:11 AM
  4. Record Count
    By jgelpi16 in forum Queries
    Replies: 4
    Last Post: 12-02-2010, 09:22 AM
  5. Form Record Count
    By Texaine in forum Forms
    Replies: 0
    Last Post: 10-19-2006, 09:07 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