Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query returning incorrect results

Status
Not open for further replies.

monkeysee

Programmer
Sep 24, 2002
201
0
0
US
I am attempting to build a query that will give a dollar balance for medical services rendered. Ie: A client may return many times for services. The clients visit may have multiple services. The client may have different methods of payments for one date of service. In other words, one visit may show a personal payment plus an insurance payment. This is what I have so far.
Client Table with the Client demographic information; and the following:

Visit table has the following fields: VisitID (primary); ClientID; Date

Service Table has the following fields: ServiceID (primary); Description; Fee

Payment Table has the following fields: PaymentID;(primary); VisitID; Amount; Date

VisitDetail table has the following fields: DetailID; VisitID; ServiceID

When I build the query, the results show a payment occurring multiple times instead of once. Here is my query:

SELECT VisitDetails.VisitDetals, Service.ServiceTypeID, Visit.VisitID, Visit.ClientID, Payments1.PaymentAmount
FROM (Visit RIGHT JOIN (VisitDetails LEFT JOIN Service ON VisitDetails.ServiceID = Service.ServiceTypeID) ON Visit.VisitID = VisitDetails.VisitID) LEFT JOIN Payments1 ON Visit.VisitID = Payments1.VisitID
WHERE (((Visit.VisitID)=[Enter]));

What am I missing?
 
Hi,

Why left and right joins? I can see an outer join between visits and payments but not services. Each visit must have at least one service it would seem to me, but you might not have a payment.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Monkeysee,

You should provide a few records from each of the tables and then try to show us how they should appear in the query. I expect one of the detail tables either VisitDetails or Payments will need to be grouped by VisitID.

Duane
Vevey, Switzerland
Hook'D on Access
MS Access MVP 2001-2016
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top