当我尝试在其他表上使用链接服务器进行选择时,我不断收到这些错误。我最终重写了查询,改变了连接的顺序,修改了一些组,然后它最终工作,但我无法理解。
SELECT TOP (100) PERCENT [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.S_COGNOME + ' ' + [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.S_NOME AS UTENTE, [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.TELEFONI.S_TEL AS TEL,
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.SEDI.S_DESCR AS PIANO, [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.S_QT AS NETNAME, [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.EMAIL.S_EMAIL AS EMAIL,
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.S_DOMINIO AS DOMINIO, [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.UFFICI.S_DESCR AS SERVIZIO, [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.AZIENDE.S_DESCR AS AZIENDA
FROM [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.AZIENDE RIGHT OUTER JOIN
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.EMAIL RIGHT OUTER JOIN
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA ON [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.EMAIL.ID_UTENTE = [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.INCID LEFT OUTER JOIN
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.SEDI ON [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.ID_SEDE = [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.SEDI.INCID LEFT OUTER JOIN
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.TELEFONI ON [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.INCID = [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.TELEFONI.ID_UTENTE LEFT OUTER JOIN
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.UFFICI ON [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.ID_UFFICIO = [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.UFFICI.INCID ON
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.AZIENDE.INCID = [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.ID_AZIENDA
ORDER BY [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.S_COGNOME, [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA.S_NOME
GO
消息4104,级别16,状态1,行18多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.EMAIL.ID_UTENTE"不可能 约束。
消息4104,级别16,状态1,行18多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.INCID"不可能 约束。
消息4104,级别16,状态1,行19多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.ID_SEDE"不可能 约束。
消息4104,级别16,状态1,行19多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.SEDI.INCID"无法受约束 消息4104,级别16,状态1,行20多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.INCID"不可能 约束。
消息4104,级别16,状态1,行20多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.TELEFONI.ID_UTENTE"不可能 约束。
消息4104,级别16,状态1,行21多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.ID_UFFICIO"不能 受约束 消息4104,级别16,状态1,行21多部分 标识符" ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.UFFICI.INCID"可以 不受约束 消息4104,级别16,状态1,行22多部分 标识符" ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.AZIENDE.INCID"可以 不受约束 消息4104,级别16,状态1,行22多部分 识别码 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.ID_AZIENDA"不能 受约束 消息4104,级别16,状态1,行13多部分 标识符" ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.S_COGNOME" 无法受约束 Msg 4104,Level 16,State 1,Line 13 The 多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.S_NOME"不可能 约束。
消息4104,级别16,状态1,行13多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.TELEFONI.S_TEL"不可能 约束。
消息4104,级别16,状态1,行14多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.SEDI.S_DESCR"不可能 约束。
消息4104,级别16,状态1,行14多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.S_QT"不可能 约束。
消息4104,级别16,状态1,行14多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.EMAIL.S_EMAIL"不可能 约束。
消息4104,级别16,状态1,行15多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.S_DOMINIO"不能 受约束 消息4104,级别16,状态1,行15多部分 标识符" ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.UFFICI.S_DESCR"可以 不受约束 消息4104,级别16,状态1,行15多部分 标识符" ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.AZIENDE.S_DESCR" 无法受约束 Msg 4104,Level 16,State 1,Line 23 The 多部分标识符 " ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.S_COGNOME"不能 受约束 消息4104,级别16,状态1,行23多部分 标识符" ZILNNM10.IT.SUB.FZ221-IT-DBA_3.0.dbo.ANAGRAFICA.S_NOME" 无法受约束。
答案 0 :(得分:0)
免责声明:这不是解决您问题的方法,但它是实现目标的重要一步。
您获得的错误意味着SQL Server无法找到您在查询中指定的标识符。由于原始查询中的每个标识符都是多部分标识符,因此难以阅读并且难以调试,因此我将所有表别名化以简化您发布的查询。
此外,将左连接与右连接混合是一种灾难,因此我尽力解决这个问题。此查询不应该删除您已收到的所有错误消息,但它应该最小化它们并帮助您找到问题。
另外,我已删除了TOP 100 PERCENT
和ORDER BY
条款。有关详细信息,请参阅我的评论。
所以这是简化的查询,我希望它有所帮助。
SELECT ANAGRAFICA.S_COGNOME + ' ' +
ANAGRAFICA.S_NOME AS UTENTE,
TELEFONI.S_TEL AS TEL,
SEDI.S_DESCR AS PIANO,
ANAGRAFICA.S_QT AS NETNAME,
EMAIL.S_EMAIL AS EMAIL,
ANAGRAFICA.S_DOMINIO AS DOMINIO,
UFFICI.S_DESCR AS SERVIZIO,
AZIENDE.S_DESCR AS AZIENDA
FROM [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.AZIENDE As AZIENDE
RIGHT JOIN
(
[ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.ANAGRAFICA As ANAGRAFICA
LEFT JOIN [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.EMAIL As EMAIL ON EMAIL.ID_UTENTE = ANAGRAFICA.INCID
LEFT JOIN [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.SEDI As SEDI ON ANAGRAFICA.ID_SEDE = SEDI.INCID
LEFT JOIN [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.TELEFONI As TELEFONI ON ANAGRAFICA.INCID = TELEFONI.ID_UTENTE
LEFT JOIN [ZILNNM10.IT.SUB].[FZ221-IT-DBA_3.0].dbo.UFFICI As UFFICI ON ANAGRAFICA.ID_UFFICIO = UFFICI.INCID
) ON AZIENDE.INCID = ANAGRAFICA.ID_AZIENDA