By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,312 Members | 2,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,312 IT Pros & Developers. It's quick & easy.

Insert Select Help

P: n/a

I need a query that looks at one table and appends another if new
customer data is added. I think I need an Insert, Select statement using
the NOT IN clause.

I need to compare Division, CustomerNumber of the two tables.

Help, Example Appreciated. Thanks
Frank
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Frank Py" <fp*@proactnet.com> wrote in message
news:3f*********************@news.frii.net...

I need a query that looks at one table and appends another if new
customer data is added. I think I need an Insert, Select statement using
the NOT IN clause.

I need to compare Division, CustomerNumber of the two tables.

Help, Example Appreciated. Thanks
Frank
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


You should post the DDL for your tables to get a more precise response, but
I guess you need something like this:

insert into dbo.TargetTable
(col1, col2, ...)
select col1, col2, ...
from dbo.SourceTable s
where not exists (
select *
from dbo.TargetTable t
where t.Division = s.Division and
t.CustomerNumber = s.CustomerNumber
)

If that guess isn't helpful, please post the DDL for both tables, including
keys.

Simon
Jul 20 '05 #2

P: n/a

Yes, that's basically it! I used MS Access to help me with some of the
syntax (dont' tell anyone). This is what I ended up with and it seems to
test good:

INSERT INTO TmemberPasswords ( Division, CustomerNumber )
SELECT AR1_CustomerMaster.Division, AR1_CustomerMaster.CustomerNumber
FROM AR1_CustomerMaster
WHERE (((AR1_CustomerMaster.Division) Not In (Select
[TmemberPasswords].[Division] From [TmemberPasswords])) AND
((AR1_CustomerMaster.CustomerNumber) Not In (Select
[TmemberPasswords].[CustomerNumber] From [TmemberPasswords])));

Thanks,
Frank
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.