Wednesday, February 22, 2006

Insert if not exists...



Doing integration tasks, you often come about the issue of transferring all "new" records from one table to another. The easiest and fastest way to do this is shown below.

Insert into TblA(TblA_Key, FldB)
select
Fld1,
...,
...
from TblB b
where not exists ( select null from TblA a where a.TblA_Key = b.TblB_Key)

0 Comments:

Post a Comment

<< Home