I am attempting to update a table in one database with information from another table in a different database. On top of that I need a third table to establish the link between the two. Here's what I have:
Update
MT.dbo.[tblPatientEmployers]
Set
MT.dbo.[tblPatientEmployers].[PatientOccupation] = RTRIM(LTRIM(T.Field3)),
MT.dbo.[tblPatientEmployers].[PatientEmploymentStatusCode] = RTRIM(LTRIM(T.Field4)),
MT.dbo.[tblPatientEmployers].[PatientEmploymentFromDate] = RTRIM(LTRIM(T.Field5)),
MT.dbo.[tblPatientEmployers].[PatientEmploymentThruDate] = RTRIM(LTRIM(T.Field6)),
MT.dbo.[tblPatientEmployers].[PatientEmployerPhoneNumber] = RTRIM(LTRIM(T.Field7)),
MT.dbo.[tblPatientEmployers].[PatientNationalEmployerID] = RTRIM(LTRIM(T.Field8)),
MT.dbo.[tblPatientEmployers].[PatientEmployerName] = RTRIM(LTRIM(T.Field9)),
MT.dbo.[tblPatientEmployers].[PatientEmployerAddress1] = RTRIM(LTRIM(T.Field11)),
MT.dbo.[tblPatientEmployers].[PatientEmployerAddress2] = RTRIM(LTRIM(T.Field12)),
MT.dbo.[tblPatientEmployers].[PatientEmployerCity] = RTRIM(LTRIM(T.Field13)),
MT.dbo.[tblPatientEmployers].[PatientEmployerStateCode] = RTRIM(LTRIM(T.Field15)),
MT.dbo.[tblPatientEmployers].[PatientEmployerZipCode] = RTRIM(LTRIM(T.Field16))
from [MT_Work].[dbo].[impHL7Xref] as T
inner join [MT_Work].[dbo].[impHL7Xref]
ON MT.dbo.tblPatients.[MedicalRecordNumber] = [MT_Work].[dbo].[impHL7Xref].MRN
WHERE T.RecordType = 'PATEMP'
Which results in the error message: Msg 4104, Level 16, State 1, Line 20 The multi-part identifier "MT.dbo.tblPatients.MedicalRecordNumber" could not be bound.
1条答案
按热度按时间mnemlml81#
Your problem is that you have never told SQL Server how your tables are all related. You need each table in the FROM clause in order to make this work: next time you write an UPDATE statement, try first writing a SELECT statement that pulls all the values you want and displays them. This will help you ensure you have the correct connections.
Assuming I'm reading your conditions right, you're looking for the following: