Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 INSERT with condition

Author  Topic 

Sunshine
Starting Member

3 Posts

Posted - 2007-08-15 : 20:24:09
I need to understand how to INSERT a record from one table to another only when a condition is meet between the two tables. Example...NewTable has new employees on it that are not on the current EmployeeTable. So, when NewTable.EmployeeNo does not match a EmployeeTable.EmployeeNo then I want to INSERT.

Can someone please help me understand what code I need to make this happen? Thanks.

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-08-15 : 21:59:54
Something like:

insert into EmployeeTable (col list) select col list from NewTable where NewTable.EmployeeNo not in (select EmployeeNo from EmployeeTable)
Go to Top of Page

Sunshine
Starting Member

3 Posts

Posted - 2007-08-16 : 05:43:07
THANK You....that worked great! I appreciate your help.
quote:
Originally posted by rmiao

Something like:

insert into EmployeeTable (col list) select col list from NewTable where NewTable.EmployeeNo not in (select EmployeeNo from EmployeeTable)

Go to Top of Page
   

- Advertisement -