Friday, March 9, 2012

Insert Select Help

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!"Frank Py" <fpy@.proactnet.com> wrote in message
news:3fd88fd6$0$199$75868355@.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|||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!

No comments:

Post a Comment