有一段时间,我已经有了一个已经工作了一个月的SQL块:
SELECT
F.[BRANCH] AS REGION
, F.[ACCOUNT]
, F.[EFFECTIVE]
, F.[POLICY]
, F.[DESC2]
, F.[DESC4]
, F.[GROSS]
, F.[COMM]
, F.[GST ON COMM]
, F.[ENTRYDATE]
, I.[TYPE]
FROM (
(SELECT [POLP - Detailed Debtors Import].*
FROM [POLP - Detailed Debtors Import]
WHERE [POLP - Detailed Debtors Import].[EFFECTIVE] <= DateValue("30/05/2012")
AND [POLP - Detailed Debtors Import].[GROSS] >= 0
AND [POLP - Detailed Debtors Import].[DESC4] IN ('RNWL', 'NEWB', 'EP')
AND [POLP - Detailed Debtors Import].[DUEYR] = 2012) AS F
INNER JOIN (SELECT IPM_ACCTXREF.* FROM IPM_ACCTXREF
WHERE IPM_ACCTXREF.TYPE
IN (SELECT [Evolve - Account Types].[Account Types]
FROM [Evolve - Account Types])
) AS I ON F.[ACCOUNT] = I.[ACCOUNT]
)
LEFT JOIN (SELECT [POLP - Detailed Debtors Import].*
FROM [POLP - Detailed Debtors Import]
WHERE [POLP - Detailed Debtors Import].[DESC4] IN ('CS', 'CANC', 'JL')
) AS S ON F.[POLICY] = S.[POLICY]
WHERE S.[POLICY] IS NULL
然后我想对DateValue参数进行更改(这就像改变说法一样简单,5到6)。
问题是我在JOIN操作中得到“语法错误”重复三次。单击它们中的每一个,查询然后显示结果表但是带有“#Name?”填写在每个领域。
不确定这里发生了什么......
答案 0 :(得分:0)
您应该重写查询,明确您需要的字段,而不是仅仅使用*
。
SELECT F.REGION,
F.ACCOUNT,
F.EFFECTIVE,
F.POLICY,
F.DESC2,
F.DESC4,
F.GROSS,
F.COMM,
F.[GST ON COMM],
F.ENTRYDATE,
I.[TYPE]
FROM ( (SELECT BRANCH AS REGION,
ACCOUNT,
EFFECTIVE,
POLICY,
DESC2,
DESC4,
GROSS,
COMM,
[GST ON COMM],
ENTRYDATE
FROM [POLP - Detailed Debtors Import]
WHERE EFFECTIVE<=Datevalue("30/05/2012")
AND GROSS>=0
AND DESC4 IN ('RNWL', 'NEWB', 'EP')
AND DUEYR=2012) AS F
INNER JOIN (SELECT [TYPE],
ACCOUNT
FROM IPM_ACCTXREF
WHERE [TYPE] IN (SELECT [Account Types]
FROM [Evolve - Account Types])) AS I
ON F.ACCOUNT=I.ACCOUNT )
LEFT JOIN (SELECT POLICY
FROM [POLP - Detailed Debtors Import]
WHERE DESC4 IN ('CS', 'CANC', 'JL')) AS S
ON F.POLICY=S.POLICY
WHERE S.POLICY IS NULL
由于LEFT JOIN
中的S
数据实际上并未在主SELECT
语句中使用,因此TYPE
的目的有点迷失。
您还使用名称{{1}}作为字段名称,这是一个保留字。
答案 1 :(得分:0)
将查询分解为子查询(通过所有讨厌的嵌套SELECT
语句)修复了问题。但不知道原因是什么(它确实用于工作)。