It seems the basic problem is that:
sum(dbo_mh1) mh1
should be:
sum(dbo_mh1) AS mh1
According to the Data Manipulation language help, this is the syntax for a SELECT:
SELECT [predicate] { * | table.* | [table.]field1 [AS alias1] [, [table.]field2 [AS alias2] [, ...]]}
FROM tableexpression [, ...] [IN externaldatabase]
[WHERE... ]
[GROUP BY... ]
[HAVING... ]
[ORDER BY... ]
[WITH OWNERACCESS OPTION]
I read that as, if you are going to give a field an alias, the "AS" must be used.
Why don't you try building your query using Access's Query Builder? Whenever I can't figure out the right syntax, I use that as my starting point.
I've never seen the "mh1 = case when b.weekno = 1 then a.mh1 else 0 end" syntax. It seems odd to me that you're repeating "a.mh1" for each case regardless of the value of "b.weekno". Also it seems that a.mh1 is not referring to a field. Isn't "a" the alias of table "mh1"? Or is "a" the alias of the table that is created by the sub-select?
Since I don't know what the "case when" is trying to accomplish, I can't be sure what a substitute could be. If I were to guess it's purpose (to set a value for the mh* aliases), that might be managed with something like "iif(b.weekno = 1,a.mh1,0) as mh1".
Everything else looks quite doable with Access's Query Builder. You might consider making the "Select empno, projno, ... from mh1 a JOIN weeks b ..." a query by itself. Then use that as your outer table "a".
You might try pasting your query into the SQL view of Query Builder and start cleaning up everywhere it presents errors. Since the syntax looks pretty complex, finding the problems using Query Builder might take a while.
Does Query Analyzer actually show you the results you expect to see? For that matter, does Query Analyzer show you the CORRECT results? That is, is the correct answer the same as the answer you expect to see?
Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org