Insert Into syntax help

G

Guest

Using Office 2003 and Windows XP;

Can someone please help me clear the syntax error I'm getting from this SQL?:

INSERT INTO
Table1 AS A
SELECT B.SAL_ADMIN_PLAN, B.PAY_GRADE,
B.ANNUAL_MIN, B.ANNUAL_MID, B.ANNUAL_MAX
FROM Table2 AS B
WHERE
(A.SAL_ADMIN_PLAN <> B.SAL_ADMIN_PLAN AND
A.PAY_GRADE <> B.PAY_GRADE);

Note that in the WHERE clause both specs must be true;
As you may be able to tell, I am not that good with SQL; please help.

Thanks much in advance.
 
J

John Spencer

You are referring to Table1 in the SELECT query. To do so, it must be in
the FROM clause of the SELECT query. I also assume that you are creating
Table1 or that Table1 has exactly 5 fields and in the order that you
specified in SELECT query.

INSERT INTO Table1 AS A
SELECT B.SAL_ADMIN_PLAN
, B.PAY_GRADE
, B.ANNUAL_MIN
, B.ANNUAL_MID
, B.ANNUAL_MAX
FROM Table2 AS B RIGHT JOIN Table1 as C
ON A.SAL_ADMIN_PLAN = C.SAL_ADMIN_PLAN AND
A.PAY_GRADE = C.PAY_GRADE
WHERE C.SAL_ADMIN_PLAN IS NULL

A good way to handle this type of thing is to construct just the Select
query first and see if it returns the records and fields you want. Once
that is done, then add the INSERT part of the append query.


--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
G

Guest

Please note that Table1 already includes some of the records in Table2; I am
trying to get only those that did not match other criteria.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top