xyb, Thanks! I had the selection criteria coming from the wrong tbl.
Cheers!
Ant
"xyb" wrote:
> On 3æ??23æ?¥, ä¸?å?1æ?¶02å??, Ant <A...@discussions.microsoft.com> wrote:
> > Hi,
> >
> > I have two tables residing in seperate DB's. I need to copy rows from one to
> > the other but only rows that don't exist in the first table. It has a
> > composite pk & must only pull certain table Ids'
> >
> > This is what I'm doing below:
> >
> > select * from DB1.dbo.Table1 db1
> > where Name = 'SomeName'
> > and not exists (select * from DB2.dbo.Table1 db2
> > where db1.Key1ID = db2.key1ID
> > and db1.Key2ID = db2.Key2ID )
> >
> > But this pulls no rows. I need to pull only the rows that don't exist in the
> > first DB. How is this done?
> >
> > Thanks very much for your help on this
> > Ant
>
> try this:)
>
> insert into DB1.dbo.Table1
> select * from DB2.dbo.Table1 db1
> where Name = 'SomeName'
> and not exists (select * from DB1.dbo.Table1 db2
> where db1.Key1ID = db2.key1ID
> and db1.Key2ID = db2.Key2ID )
>
>