New to SQL and need help writing a query

Hello all

I am new to using SQL and was asked to write a query. I set everything up but I still keep getting errors. Below is my query:

SELECT distinct
, SharedLocation.Person.PatientExtension.PatientLastNM
, SharedLocation.Person.PatientExtension.PatientFirstNM
, SharedLocation.Person.PatientExtension.PatientMiddleNM
, Epic.Finance.HospitalAccount.PatientEncounterID
, SharedLocation.Person.PatientExtension.Ethnicity01NM
, SharedLocation.Person.PatientExtension.Race01DSC
, Loc.RevenueLocationNM

FROM Epic.Finance.HospitalAccount HA

 INNER JOIN SharedLocal.Person.PatientExtension 
 ON Epic.Finance.HospitalAccount.PatientMRN = SharedLocal.Person.PatientExtension.DFCIMRN
 INNER JOIN Epic.Finance.Coverage 
 INNER JOIN Epic.Finance.Coverage
 ON Epic.Finance.Coverage.PayorID = Epic.Reference.PayorPayorID
 ON Epic.Finance.HospitalAccount.CoverageID = Epic.Finance.Coverage.CoverageID
 LEFT JOIN Epic.Finance.HospitalTransaction HT ON HA.HospitalAccountID = HT.HospitalAccountID
 LEFT JOIN Epic.Patient.[Identity] I on HA.PatientID = I.PatientID		
 LEFT JOIN Epic.Reference.[Location] LOC ON HA.[DischargeEpicLocationID] = LOC.LocationID

-------- to identify DFCI patients and relevant records ----------
-- Only DFCI patients
I.IdentityTypeID = '109'
AND LEFT(Loc.RevenueLocationNM,4) = 'Dana'
-- Specifyin Fiscal Year
AND CASE WHEN Month(HA.DischargeDTS) > 9 THEN YEAR(HA.DischargeDTS) + 1 ELSE YEAR(HA.DischargeDTS) END in (2019, 2020)

This is the error I am getting:

Msg 4104, Level 16, State 1, Line 18
The multi-part identifier "Epic.Finance.HospitalAccount.PatientMRN" could not be bound.

Msg 4104, Level 16, State 1, Line 20
The multi-part identifier "Epic.Finance.HospitalAccount.CoverageID" could not be bound.

Msg 1013, Level 16, State 1, Line 5
The objects "Epic.Finance.Coverage" and "Epic.Finance.Coverage" in the FROM clause have the same exposed names. Use correlation names to distinguish them.

Can anyone help me create this query? Any assistance would be greatly appreciated.



i think your problem is with this ..

you are using an alias for table ... Epic.Finance.HospitalAccount HA

either remove HA
use HA.column_name everywhere !!

1 Like