473,396 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.
Nov 3 '07 #1
7 1315
Jim Doherty
897 Expert 512MB
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT PatientAccounts.PatientNo, Patient.FirstName, Patient.LastName, PatientAccounts.Date, DateDiff("d",[PatientAccounts].[Date],Date()) AS DaysSince
  3. FROM (PatientAccounts LEFT JOIN Patient ON PatientAccounts.PatientNo = Patient.PatientNo) LEFT JOIN Payment ON (PatientAccounts.ProviderNo = Payment.ProviderNo) AND (PatientAccounts.PatientNo = Payment.PatientNo)
  4. WHERE (((DateDiff("d",[PatientAccounts].[Date],Date()))>42) AND ((Payment.PaymentDate) Is Null));
  5.  

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 :)
Nov 3 '07 #2
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.PatientNo 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.
Nov 4 '07 #3
Jim Doherty
897 Expert 512MB
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.PatientNo 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
Nov 4 '07 #4
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:
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT PatientAccount.PatientNo, Patient.FirstName, Patient.LastName, PatientAccount.Date, DateDiff("d",[PatientAccount].[Date],Date()) AS DaysSince
  3. FROM (PatientAccount LEFT JOIN Patient ON PatientAccount.PatientNo = Patient.PatientNo) LEFT JOIN Payment ON (PatientAccount.ProviderNo = Payment.ProviderNo) AND (PatientAccounts.PatientNo = Payment.PatientNo)
  4. WHERE (((DateDiff("d",[PatientAccount].[Date],Date()))>42) AND ((Payment.PaymentDate) Is Null)); 
  5.  
Error occurs at second statement, AND (PatientAccounts.PatientNo = Payment.PatientNo) saying "syntax error in join operation"
Nov 4 '07 #5
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.
Nov 4 '07 #6
ahhh yes finally got it, all the spaces between the words was the main problem. Thanks for the help, and great query:D
Nov 4 '07 #7
Jim Doherty
897 Expert 512MB
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 :)
Nov 4 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Laphan | last post by:
Hi Guys I don't want to keep asking for your help all the time on each individual query, so could you please help me to break the myths on the following: 1) I have 2 tables. Once is called...
3
by: rong.guo | last post by:
Hello group! I am having a problem with simplying my query... I would like to get customers' balance info based on how many months since they opened their accounts. The tricky part here is...
3
by: b_naick | last post by:
I have 2 tables: - Users, with fields id and fullName - Accounts, with accntID, userID, accntName, Active I need to write a query which lists all the users, along with the number of accounts...
6
by: Steven D.Arnold | last post by:
I have a query which does not use column indexes that it should use. I have discovered some interesting behaviors of Postgres which may indicate a bug in the database's query planning. Take a...
2
by: jh8735 | last post by:
I use Access to run reports from various pieces of financial data. The one query that I have been unable to produce, but need is the following: A query that yields all accounts from a person...
5
by: jmartineau | last post by:
Hello, Here is a brief summary: Table 1 = All Accounts - with fields such as Customer ID and Account # Table 2 = Deposit Balance Table - with fields such as Account #, Balance
2
by: Stephenoja | last post by:
Hello Guys, I have a problem that has to do with Aging Accounts Receivable. I have three tables with customer account numbers, customer names, customer balances for the years 2003, 2004 and...
6
by: Darren | last post by:
I'm trying to build a query but struggling on how to achieve the linking. For examples, I have a table and a view similar to this.. Table: Accounts ACC_REF Char(3), DESCRIPTION VARCHAR(30),...
5
by: vegak18 | last post by:
Dear Experts, I was was wondering if there was some way to specify output properties of a make table query. Specifically, I am haivng a problem with numbers being specified as text. while I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.