我有2个主表AGENCY
和PERSONEL
,我可以从中选择:
-- two primary tables -- works well
select
-- AT_AGENCY_STAFF.PERS_SSN as PERS_SSN
an_agency_table.U_AGENCY_NUMBER as AGENCY_NUMBER,
an_personel_id_table.U_PERSONNEL_ID as PERSONNEL_ID
from
[dbo].[an_agency_table],
[dbo].[an_personel_id_table]
-- left outer join [dbo].[AT_AGENCY_STAFF] on AT_AGENCY_STAFF.id_an_agency_table = [dbo].[an_agency_table].id_an_agency_table
where
[dbo].[an_personel_id_table].[U_PERSONNEL_ID] = 1
and [dbo].[an_agency_table].[U_AGENCY_NUMBER] = '777778'
当仅使用一个主表时,我可以通过左外部联接(如果没有人员,则可以连接AGENCY_STAFF)>
-- one primary table and left outer join -- works well select AT_AGENCY_STAFF.PERS_SSN as PERS_SSN , an_agency_table.U_AGENCY_NUMBER as AGENCY_NUMBER -- , an_personel_id_table.U_PERSONNEL_ID as PERSONNEL_ID from [dbo].[an_agency_table] -- ,[dbo].[an_personel_id_table] left outer join [dbo].[AT_AGENCY_STAFF] on AT_AGENCY_STAFF.id_an_agency_table = [dbo].[an_agency_table].id_an_agency_table where -- [dbo].[an_personel_id_table].[U_PERSONNEL_ID]=1 and [dbo].[an_agency_table].[U_AGENCY_NUMBER]='777778'
但是当我同时使用两个主表并被遗漏连接到其中一个时,我会报错:
-- two primary tables and left outer join -- Msg 4104, Level 16, State 1, Line 9 -- The multi-part identifier "dbo.an_agency_table.id_an_agency_table" could not be bound. select AT_AGENCY_STAFF.PERS_SSN as PERS_SSN , an_agency_table.U_AGENCY_NUMBER as AGENCY_NUMBER , an_personel_id_table.U_PERSONNEL_ID as PERSONNEL_ID from [dbo].[an_agency_table] ,[dbo].[an_personel_id_table] left outer join [dbo].[AT_AGENCY_STAFF] on AT_AGENCY_STAFF.id_an_agency_table = [dbo].[an_agency_table].id_an_agency_table where -- [dbo].[an_personel_id_table].[U_PERSONNEL_ID]=1 and [dbo].[an_agency_table].[U_AGENCY_NUMBER]='777778'
有关如何解决此问题的任何建议?
我有2个主表AGENCY和PERSONEL,我可以从中选择:-两个主表-可以很好地选择-AT_AGENCY_STAFF.PERS_SSN作为PERS_SSN an_agency_table.U_AGENCY_NUMBER作为...
请尝试使用下面的格式,不过我对您的命名约定没有过多的注意。