Ok- As I mentioned earlier I have more than one field - but in this case ONLY CustomerID is generated...In the code below, assume PatID = CustomerID and PracID = SupplierID INSERT INTO dbo.TablePatient (PatID, PracID, PersonID, PatientGuidDigest, BirthYear, Gender, DeathDate,Ethnicity, PatientType, Registered, RegistrationStartDate, RegistrationEndDate)SELECT o.PracID, o.PersonID, o.PatientGuidDigest, o.BirthYear, o.Gender, o.DeathDate, o.Ethnicity, o.PatientType, o.Registered, o.RegistrationStartDate, o.RegistrationEndDate, c.ID + 10000FROM dbo.QryPatientExtraction o OUTER APPLY( SELECT TOP (1) ISNULL (m.PatID, o.PracID) FROM dbo.TablePatient m WHERE o.Pracid = m.pracid and o.PersonID = m.PersonID and o.PatientGuidDigest = m.PatientGuidDigest ORDER BY o.PatID DESC ) c(ID)
Receive the error: Invalid column name 'PatID'I have checked the column PatID has been created in the table design view. Also note, all the other fields are present in QryPatientExtraction with the exception of PATID. Which I would like to have the as shown in blog #1Thanks