0

the following is my ms access sql query

    SELECT '2012/8'      AS [Period],
       yearmonth.[Monthno (PS)] AS monthno,
       [assignment_2012].[cluster code] AS cluster,
       'Transfer out' AS Remark,
       -1*Count(*)      AS [number],
       '5'           AS [sorting]
FROM  [assignment_2012] 
INNER JOIN namesort ON [assignment_2012].post = namesort.post 
INNER JOIN yearmonth ON [assignment_2012].[year month]=yearmonth.[Year Month (HM)] 
INNER JOIN
       (SELECT empid
                     FROM   (SELECT empid,
                                    [cluster],
                                    Count(*) AS [empid no]
                             FROM   (SELECT [ID] as empid,
                                            [Cluster Code] as cluster 
                                     FROM   [assignment_2012]
                                            INNER JOIN yearmonth
                                                    ON [assignment_2012].[year month]
                                                       =
                                                       yearmonth.[Year Month (HM)]
                                     WHERE  yearmonth.[Monthno (PS)] = 243
                                            AND [assignment_2012].hc_adj = 1
                                            AND [assignment_2012].term <> 'Temporary'
                                     UNION
                                     SELECT empid,
                                            [cluster]
                                     FROM   [2012]
                                     WHERE  monthno = 244
                                            AND [2012].term <> 'Temporary'
                                            AND ( div <> 'XXX'
                                                   OR div IS NULL )
                                            AND hc = 1)
                             GROUP  BY [empid],
                                       [cluster]
                             HAVING Count(*) = 1)
                     GROUP  BY empid
                     HAVING Count(*) > 1) As Emps
ON [assignment_2012]].EmpID = Emps.EmpID
WHERE  yearmonth.[Monthno (PS)] = 243
       AND [assignment_2012].hc_adj = 1
       AND yearmonth.[Monthno (PS)] BETWEEN namesort.monthno_start AND namesort.monthno_end
       AND [assignment_2012].term <> 'Temporary'
GROUP  BY yearmonth.[Monthno (PS)], [assignment_2012].[cluster code]

When i run the query, it prompt message that "syntax error (missing operator) in query expression '[assignment_2012].post = namesort.post INNER JOING........"

i found that it return error if it include "INNER JOIN yearmonth ON [assignment_2012].[year month]=yearmonth.[Year Month (HM)]" in the sql statement

2
  • Have you tried to remove the different selections one by one to locate precisely where the error is? Commented Dec 27, 2012 at 8:06
  • yes, i had tried it. i found that it return error if it include "INNER JOIN yearmonth ON [assignment_2012].[year month]=yearmonth.[Year Month (HM)]" in the sql statement Commented Dec 27, 2012 at 8:11

1 Answer 1

0

i had revised the INNER JOIN statement of yearmonth table and it works now.

SELECT '2012/8' AS Period, YearMonth.[Monthno (PS)], assignment_2012.[cluster code] AS cluster, 'Transfer out' AS Remark, -1*Count(*) AS [number], '5' AS sorting
FROM YearMonth INNER JOIN ((assignment_2012 INNER JOIN namesort ON assignment_2012.post = namesort.post) INNER JOIN (SELECT empid
                     FROM   (SELECT empid,
                                    [cluster],
                                    Count(*) AS [empid no]
                             FROM   (SELECT [HKID] as empid,
                                            [Cluster Code] as cluster 
                                     FROM   [assignment_2012]
                                            INNER JOIN yearmonth
                                                    ON [assignment_2012].[year month]
                                                       =
                                                       yearmonth.[Year Month (HM)]
                                     WHERE  yearmonth.[Monthno (PS)] = 243
                                            AND [assignment_2012].hc_adj = 1
                                            AND [assignment_2012].term <> 'Temporary'
                                     UNION
                                     SELECT empid,
                                            [cluster]
                                     FROM   [2012]
                                     WHERE  monthno = 244
                                            AND [2012].term <> 'Temporary'
                                            AND ( div <> 'XXX'
                                                   OR div IS NULL )
                                            AND hc = 1)
                             GROUP  BY [empid],
                                       [cluster]
                             HAVING Count(*) = 1)
                     GROUP  BY empid
                     HAVING Count(*) > 1)  AS Emps ON assignment_2012.ID = Emps.EmpID) ON YearMonth.[Year Month (HM)] = assignment_2012.[Year Month]
WHERE (((assignment_2012.hc_adj)=1) AND ((assignment_2012.term)<>'Temporary'))
GROUP BY YearMonth.[Monthno (PS)], assignment_2012.[cluster code];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.