There seems to be a typo in the SQL code you provided; on line:
Left Join GLPOST [P] on MT.MonthNo = Month(P.[Date]
There is a closing parenthesis missing.
One should read:
Left Join GLPOST [P] on MT.MonthNo = Month(P.[Date])
Hope this helps.
is included in GROUP BY clause, I would go for a HAVING instead of a WHERE clause for this column. Also, you do not really need the [D] table here (the only column you are retrieving from it can be obtained from P.GLDATAID). Thus:
SELECT MT.MonthNo, MT.YearNo, P.GLDATAID, Sum(P.DebitAmt), Sum(P.CreditAmt)
FROM @MonthTable [MT]
LEFT JOIN GLPOST [P] on MT.MonthNo = Month(P.[Date])
GROUP BY MT.MonthNo, MT.YearNo, P.GLDATAID
ORDER BY P.GLDATAID, MT.yearNo, MT.MonthNo