Query for Deliquent Accounts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geebanga88
    New Member
    • Aug 2007
    • 62

    Query for Deliquent Accounts

    Hi i have the follow Database schema:

    Patient:
    PK PatientNo
    FirstName
    LastName

    PatientAccount
    P/FK PatientNo
    P/FK ProivderNo
    PK Date

    Payment
    PK Date
    P/Fk PatientNo
    P/Fk ProivderNo
    P/Fk PaymentDate

    Was wondering how i could get(select) all the patients with accounts that havent payed thier accounts within 42 days of the creation date.
    References will also be most welcome.
    Last edited by geebanga88; Nov 3 '07, 11:24 AM. Reason: clean up
  • Jim Doherty
    Recognized Expert Contributor
    • Aug 2007
    • 897

    #2
    Originally posted by geebanga88
    Hi i have the follow Database schema:

    Patient:
    PK PatientNo
    FirstName
    LastName

    PatientAccount
    P/FK PatientNo
    P/FK ProivderNo
    PK Date

    Payment
    PK Date
    P/Fk PatientNo
    P/Fk ProivderNo
    P/Fk PaymentDate

    Was wondering how i could get(select) all the patients with accounts that havent payed thier accounts within 42 days of the creation date.
    References will also be most welcome.


    Assuming there to be a correllation between ProviderNo in Patient Accounts and ProviderNo in Payment then the date difference in days is calculated from the Date column in PatientAccounts and the current date using the DateDiff function. It is included as column in itself as part of the SQL. You can then control the dataset based on that ie greater than 42 (>42) and only where the PaymentDate is null

    Code:
     
    SELECT PatientAccounts.PatientNo, Patient.FirstName, Patient.LastName, PatientAccounts.Date, DateDiff("d",[PatientAccounts].[Date],Date()) AS DaysSince
    FROM (PatientAccounts LEFT JOIN Patient ON PatientAccounts.PatientNo = Patient.PatientNo) LEFT JOIN Payment ON (PatientAccounts.ProviderNo = Payment.ProviderNo) AND (PatientAccounts.PatientNo = Payment.PatientNo)
    WHERE (((DateDiff("d",[PatientAccounts].[Date],Date()))>42) AND ((Payment.PaymentDate) Is Null));

    The above SQL mirrors your table and fieldnames which thankfully you posted therefore you should just be able to copy and paste the above into the Access query design SQL window, then view it in design and see if it befits your needs.

    Regards

    Jim :)

    Comment

    • geebanga88
      New Member
      • Aug 2007
      • 62

      #3
      ahh thanks for the qry, i have the table patientaccounts as "patient account" in access so once i edited that e.g SELECT Patient Account.Patient No it comes up with missing operator? do i needed to put a type of brackets around it or leave out the space. If i put it as one word it a syntax error has occured.
      Last edited by geebanga88; Nov 4 '07, 01:15 AM. Reason: adding note

      Comment

      • Jim Doherty
        Recognized Expert Contributor
        • Aug 2007
        • 897

        #4
        Originally posted by geebanga88
        ahh thanks for the qry, i have the table patientaccounts as "patient account" in access so once i edited that e.g SELECT Patient Account.Patient No it comes up with missing operator? do i needed to put a type of brackets around it or leave out the space. If i put it as one word it a syntax error has occured.

        Keep spaces out of table names and fieldnames. If you are unable to do that then wrap in square brackets ie [Patient Account] if you still have problem post your SQL back and I will look at it :)

        Jim

        Comment

        • geebanga88
          New Member
          • Aug 2007
          • 62

          #5
          Ok i tried wraping it but still failed with an syntax error join. I then renamed it so it has no spaces, but i get the same error so wraping it produced the same result. (meaing wraping can work :D)

          Statement:
          Code:
           
          SELECT PatientAccount.PatientNo, Patient.FirstName, Patient.LastName, PatientAccount.Date, DateDiff("d",[PatientAccount].[Date],Date()) AS DaysSince
          FROM (PatientAccount LEFT JOIN Patient ON PatientAccount.PatientNo = Patient.PatientNo) LEFT JOIN Payment ON (PatientAccount.ProviderNo = Payment.ProviderNo) AND (PatientAccounts.PatientNo = Payment.PatientNo)
          WHERE (((DateDiff("d",[PatientAccount].[Date],Date()))>42) AND ((Payment.PaymentDate) Is Null));
          Error occurs at second statement, AND (PatientAccount s.PatientNo = Payment.Patient No) saying "syntax error in join operation"

          Comment

          • geebanga88
            New Member
            • Aug 2007
            • 62

            #6
            AAHH i think i noe why this is happening i have, Patient.Patinet No and PatientAccount. PatientNo (no space) same kinds of error.Also made sum spaces in other columns so ill get back to you once i have fixed these errors.
            Last edited by geebanga88; Nov 4 '07, 05:17 AM. Reason: Add detail

            Comment

            • geebanga88
              New Member
              • Aug 2007
              • 62

              #7
              ahhh yes finally got it, all the spaces between the words was the main problem. Thanks for the help, and great query:D

              Comment

              • Jim Doherty
                Recognized Expert Contributor
                • Aug 2007
                • 897

                #8
                Originally posted by geebanga88
                ahhh yes finally got it, all the spaces between the words was the main problem. Thanks for the help, and great query:D
                You're welcome finally got there in the end :) spaces cause untold problems best to keep to a discipline of 'none at all', that way brackets never enter into it and it scales up much easier too.

                Regards

                Jim :)

                Comment

                Working...