For some time, I’ve had this block of SQL which has worked for a month:
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
I then wanted to make a change to the DateValue parameter (which would be as simple as changing say, the 5 to a 6).
Problem then is that I get a “Syntax error in JOIN operation” repeated three times. Clicking through each of them, the query then displays the resulting table but with “#Name?” populated in each field.
Not sure what’s happening here…
Breaking the query down into subqueries (getting past all that nasty nested
SELECTstatements) fixed the issue. Don’t know what the cause was in the first place (it did use to work) though.