Need help with SQL statement

T

Tara

I need help with the structure of the following SQL statement. The Append
query works, but I only want it to append records that have not already been
appended. I know the WHERE statement needs to be adjusted, but I'm not sure
how. Thanks for any input!

INSERT INTO tblTransition( ScreenNum )
SELECT tblDemographics.ScreenNum
FROM tblDemographics
WHERE(((tblDemographics.ScreenNum)=[Forms]![frmTransition]![ScreenNum]));
 
J

John W. Vinson

I need help with the structure of the following SQL statement. The Append
query works, but I only want it to append records that have not already been
appended. I know the WHERE statement needs to be adjusted, but I'm not sure
how. Thanks for any input!

INSERT INTO tblTransition( ScreenNum )
SELECT tblDemographics.ScreenNum
FROM tblDemographics
WHERE(((tblDemographics.ScreenNum)=[Forms]![frmTransition]![ScreenNum]));

Actually, the WHERE clause is not the best place: use a JOIN instead to append
only UNMATCHED records:

INSERT INTO tblTransition(ScreenNum)
SELECT tblDemographics.ScreenNum
FROM tblDemographics LEFT JOIN tblTransition
ON tblDemographics.ScreenNum = tblTransition.ScreenNum
WHERE(((tblDemographics.ScreenNum)=[Forms]![frmTransition]![ScreenNum]))
AND tblTransition.ScreenNum IS NULL;

HOWEVER... since you're just inserting one record, and one field, why use an
append query at all? What's frmTransition's Recordsource - can't you just
update the table directly, perhaps using a combo box based on tblDemographics
to select the screennum?
 
K

KARL DEWEY

INSERT INTO tblTransition( ScreenNum )
SELECT tblDemographics.ScreenNum
FROM tblDemographics
WHERE ([tblDemographics].[ScreenNum] <> [Forms]![frmTransition]![ScreenNum]);
 
T

Tara

Thanks for getting back with me John. The recordsource for frmTransition is
a query that is based on a different table in the database, so unfortunately,
I can't update the table directly. The JOIN solution you gave worked
perfectly though. Thank you!

John W. Vinson said:
I need help with the structure of the following SQL statement. The Append
query works, but I only want it to append records that have not already been
appended. I know the WHERE statement needs to be adjusted, but I'm not sure
how. Thanks for any input!

INSERT INTO tblTransition( ScreenNum )
SELECT tblDemographics.ScreenNum
FROM tblDemographics
WHERE(((tblDemographics.ScreenNum)=[Forms]![frmTransition]![ScreenNum]));

Actually, the WHERE clause is not the best place: use a JOIN instead to append
only UNMATCHED records:

INSERT INTO tblTransition(ScreenNum)
SELECT tblDemographics.ScreenNum
FROM tblDemographics LEFT JOIN tblTransition
ON tblDemographics.ScreenNum = tblTransition.ScreenNum
WHERE(((tblDemographics.ScreenNum)=[Forms]![frmTransition]![ScreenNum]))
AND tblTransition.ScreenNum IS NULL;

HOWEVER... since you're just inserting one record, and one field, why use an
append query at all? What's frmTransition's Recordsource - can't you just
update the table directly, perhaps using a combo box based on tblDemographics
to select the screennum?
 
K

KARL DEWEY

Did not read it correctly.
--
Build a little, test a little.


KARL DEWEY said:
INSERT INTO tblTransition( ScreenNum )
SELECT tblDemographics.ScreenNum
FROM tblDemographics
WHERE ([tblDemographics].[ScreenNum] <> [Forms]![frmTransition]![ScreenNum]);

--
Build a little, test a little.


Tara said:
I need help with the structure of the following SQL statement. The Append
query works, but I only want it to append records that have not already been
appended. I know the WHERE statement needs to be adjusted, but I'm not sure
how. Thanks for any input!

INSERT INTO tblTransition( ScreenNum )
SELECT tblDemographics.ScreenNum
FROM tblDemographics
WHERE(((tblDemographics.ScreenNum)=[Forms]![frmTransition]![ScreenNum]));
 

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