Incorrect Data Returned

  • Thread starter Thread starter MarieG
  • Start date Start date
M

MarieG

Hi,

I'm linking 3 tables.. when I run the query, the info for patient visit id,
ticket number, Date of Service, Description, vbalance, logged date, and
logged by are a wrong. There should only be 4 rows of info for the
patientvisit id number 30865, but it returns many more than that, of which
most should be associated with different patientvisidid numbers.. ideas?

Thanks so much!!

SELECT [dbo_vBilling_Visits-TMC002-OGA].Company,
[dbo_vBilling_Visits-TMC002-OGA].VisitOwner,
[dbo_vBilling_Visits-TMC002-OGA].Patient,
[dbo_PatientCorrespondence-TMC002-OGA].PatientProfileId,
[dbo_PatientCorrespondence-TMC002-OGA].PatientVisitId,
[dbo_vBilling_Visits-TMC002-OGA].TicketNumber,
[dbo_vBilling_Visits-TMC002-OGA].DateOfService,
[dbo_PatientCorrespondence-TMC002-OGA].Source,
[dbo_PatientCorrespondence-TMC002-OGA].UserId,
[dbo_PatientCorrespondence-TMC002-OGA].Description,
[dbo_PatientCorrespondence-TMC002-OGA].DescriptionLong,
[dbo_PatientCorrespondence-TMC002-OGA].NextContactDate,
[dbo_vBilling_Visits-TMC002-OGA].vBalance,
[dbo_PatientInfoLog-TMC002-OGA].Created AS [Logged Date],
[dbo_PatientInfoLog-TMC002-OGA].CreatedBy AS [Logged by]
FROM [Date Pulled], [dbo_vBilling_Visits-TMC002-OGA] INNER JOIN
([dbo_PatientCorrespondence-TMC002-OGA] INNER JOIN
[dbo_PatientInfoLog-TMC002-OGA] ON
[dbo_PatientCorrespondence-TMC002-OGA].PatientVisitId =
[dbo_PatientInfoLog-TMC002-OGA].PatientVisitId) ON
([dbo_vBilling_Visits-TMC002-OGA].PatientVisitID =
[dbo_PatientInfoLog-TMC002-OGA].PatientVisitId) AND
([dbo_vBilling_Visits-TMC002-OGA].PatientVisitID =
[dbo_PatientCorrespondence-TMC002-OGA].PatientVisitId)
WHERE ((([dbo_PatientCorrespondence-TMC002-OGA].PatientProfileId)=24008) AND
(([dbo_PatientInfoLog-TMC002-OGA].Created) Between [FROM DATE] And [TO DATE])
AND (([dbo_PatientInfoLog-TMC002-OGA].CreatedBy) Like "TMC-ROSE*" Or
([dbo_PatientInfoLog-TMC002-OGA].CreatedBy) Like "TMC-KRISTINA*" Or
([dbo_PatientInfoLog-TMC002-OGA].CreatedBy) Like "TMC-SANDRA*"));
 
Check the fields on both sides of the of both INNER JOINS. At least one side
must be a primary key to ensure not getting in strange records. It looks like
you have multiple fields on each side of the join. All the fields need to be
part of a composite primary key and that PK must only have those fields -
nothing extra.
 
Back
Top