我正在尝试修复已经开始失败的MS Access查询。这是由几年前离开的其他人建造的系统,所以我正在倒退去理解它。失败的部分是一个连接其他两个子查询的查询。
如果我在查询连接上运行'SELECT *',它会毫无问题地返回数据。但是,只要我尝试定义一个特定的字段,它就会失败并显示无效的消息“查询过于复杂”。
所以,这会返回数据没问题:
SELECT * FROM 530a_WIPIncomeShareByResource
INNER JOIN 510_AllInvoicesCreditsInvWIP
ON [530a_WIPIncomeShareByResource].WIPDocApplicable
= [510_AllInvoicesCreditsInvWIP].No_
WITH OWNERACCESS OPTION;
但是,如果我从连接中的两个查询中的任何一个定义任何字段,那么它会出错,从而给出“查询过于复杂”的错误。所以,这失败了,例如:
SELECT [510_AllInvoicesCreditsInvWIP].Status
FROM 530a_WIPIncomeShareByResource
INNER JOIN 510_AllInvoicesCreditsInvWIP
ON [530a_WIPIncomeShareByResource].WIPDocApplicable
= [510_AllInvoicesCreditsInvWIP].No_
WITH OWNERACCESS OPTION;
我已经分别检查了连接中引用的两个子查询(530a_WIPIncomeShareByResource和510_AllInvoicesCreditsInvWIP),这些子查询都执行正常和返回数据。然而,加入这两者并不是。
我对Access经验不足,所以无论如何都会感激不尽!
嗨,这是子查询的代码:
530a_WIPIncomeShareByResource:
SELECT [502_WIP_DocApplicable].No_ AS [Resource No_],
[502_WIP_DocApplicable].[Posting Date],
[502_WIP_DocApplicable].WIPDocApplicable,
[502_WIP_DocApplicable].WIPOpen,
Sum(IIf([Work Type code]<>"WRITEOFF"
And [Type]<>3
And [Work Type code]<>"DISBURSE"
And [Work Type code]<>"DIRRESP"
And [Work Type code]<>"TAXJ"
And [Work Type code]<>"INVMON"
And [Work Type code]<>"CUST"
And [NAVTCIWORKTYPE-FEETYPE.Disbursement]<>1,[WIPValue],0)) AS QualWIP,
Sum(IIf([Work Type code]="WRITEOFF",[WIPValue],0)) AS NonQualWOWIP,
Sum(IIf([Work Type code]="DISBURSE"
Or [Work Type code]="XTNLPERCEN"
Or [Type]=3
Or [NAVTCIWORKTYPE-FEETYPE.Disbursement]=1,[WIPValue],0)) AS DISBURSE,
Sum(IIf([Work Type code]="DIRRESP"
Or [Work Type code]="TAXJ"
Or [Work Type code]="INVMON"
Or [Work Type code]="CUST",[WIPValue],0)) AS FIXEDFEE,
Sum([502_WIP_DocApplicable].WIPValue) AS TotalWIP
FROM [NAVTCIWORKTYPE-FEETYPE]
INNER JOIN 502_WIP_DocApplicable
ON [NAVTCIWORKTYPE-FEETYPE].Code = [502_WIP_DocApplicable].[Work Type Code]
GROUP BY [502_WIP_DocApplicable].No_,
[502_WIP_DocApplicable].[Posting Date],
[502_WIP_DocApplicable].WIPDocApplicable,
[502_WIP_DocApplicable].WIPOpen
WITH OWNERACCESS OPTION;
和第二个:
510_AllInvoicesCreditsInvWIP
SELECT [510_AllInvoicesCredits].[Job No_],
[510_AllInvoicesCredits].No_,
[510_AllInvoicesCredits].[Invoice Date1] AS [Invoice Date],
[510_AllInvoicesCredits].Status,
[510_AllInvoicesCredits].[Invoice No_],
[510_AllInvoicesCredits].REVERSED,
[510_AllInvoicesCredits].[Reversal Document No_],
[510_AllInvoicesCredits].[Reversal Document Date],
[510_AllInvoicesCredits].Reference,
IIf([DocType]="Credit",[TotalBill],([TotalBill]-[FTRaised]+(-
(IIf(IsNull([FTWO]),0,
IIf([TotalBill]<=-0.01,-[FTWO],[FTWO]))))-
(IIf([TotalBill]<0,-[DISBURSE],[DISBURSE]))-
(IIf([TotalBill]<0,-[FIXEDFEE],[FIXEDFEE]))-
(IIf([TotalBill]<0,-[XTNLPERCENSHARE],[XTNLPERCENSHARE]))-
(IIf([TotalBill]<0,-[FIXEDFEESHARE],[FIXEDFEESHARE])))) AS IncomeToAlloc,
[510_AllInvoicesCredits].TotalBill,
[510_AllInvoicesCredits].XTNLPERCENSHARE,
[510_AllInvoicesCredits].FIXEDFEESHARE,
[520a_WIPAnalysis1_WIP].QualWIP,
[520a_WIPAnalysis1_WIP].NonQualWOWIP,
[520a_WIPAnalysis1_WIP].DISBURSE,
[520a_WIPAnalysis1_WIP].TotalWIP,
[510_AllInvoicesCredits].FTRaised AS FTR,
IIf(IsNull([FTWO]),0,IIf([TotalBill]<0,-[FTWO],[FTWO])) AS FTWO1,
[520a_WIPAnalysis1_WIP].GenCFWIPUsed,
[510_AllInvoicesCredits].GenCF AS GenCFRaised,
[510_AllInvoicesCredits].WOPROVRaised AS WOPROVR,
[520b_WIPAnalysis2_FT].WOPROVWO AS WOPROVUsed,
[520a_WIPAnalysis1_WIP].FIXEDFEE,
[510_AllInvoicesCredits].DocType,
[510_AllInvoicesCredits].Doc
FROM (510_AllInvoicesCredits LEFT JOIN 520a_WIPAnalysis1_WIP
ON [510_AllInvoicesCredits].No_ = [520a_WIPAnalysis1_WIP].WIPDocApplicable)
LEFT JOIN 520b_WIPAnalysis2_FT
ON [510_AllInvoicesCredits].No_ = [520b_WIPAnalysis2_FT].FTDocApplicable
WHERE ((([510_AllInvoicesCredits].REVERSED)<>1))
ORDER BY [510_AllInvoicesCredits].[Invoice Date1]
WITH OWNERACCESS OPTION;
整个Access系统是一层一层的查询。破译真的很头疼!但是,上面运行得很好。