Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tricky SQL Update Problem 1

Status
Not open for further replies.

rap43

Programmer
Apr 21, 2003
13
US
Here is a "brain teaser". I'm on SQL Server 6.5 and trying to write a SQL Update query (or Add query) to add some Job Descriptions from one table to the other WITHOUT adding or overlaying the Job Descriptions on the receiving table that are already there (they are newer and I want to keep them).

I have the SQL server tblJobDescriptions (latest and greatest job descriptions)and the tblJobDescriptions2 as another table within the saem DB. The fields in both DB's have the same field names as:

JobName
JobDescription
CreateUser
CreateDate

Again - I don't want to overlay or add any tblJobDescriptions2 records (using JobName as the matching criteria) that are already there, I only want to add the records whose Jobnames that are not already there.

Thanks!
 
Here is an example that will insert all new records. You may need more joins, if jobname doesn't define the table. You may want to run it without the insert to check if it works correctly.


insert into tblJobDescriptions
select * from tblJobDescriptions2 t2
where not exists (select * from tblJobDescriptions t
where t.jobname = t2.jobname)

Dodge20
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top