Jun 22, 2007 #1 jms493 MIS Joined May 16, 2007 Messages 11 Location US I want to run a a query at any time and only inserts/appends data to the table if the record does not exist. No duplicate rows. How can write this?
I want to run a a query at any time and only inserts/appends data to the table if the record does not exist. No duplicate rows. How can write this?
Jun 22, 2007 #2 AlexCuse Programmer Joined Apr 13, 2006 Messages 5,416 Location US If you have a (real) primary key, you can use a left join. Code: insert into myTable select a.* from myOtherTable a left join myTable b on a.PK_Value = b.PK_Value where b.PK_Value is null Hope this helps, Alex Ignorance of certain subjects is a great part of wisdom Upvote 0 Downvote
If you have a (real) primary key, you can use a left join. Code: insert into myTable select a.* from myOtherTable a left join myTable b on a.PK_Value = b.PK_Value where b.PK_Value is null Hope this helps, Alex Ignorance of certain subjects is a great part of wisdom
Jun 22, 2007 1 #3 SQLDenis Programmer Joined Oct 1, 2005 Messages 5,575 Location US if not exists (select * from table where key ='somevalues here') insert table select <values> Denis The SQL Menace -------------------- SQL Server Code,Tips and Tricks, Performance Tuning SQLBlog.com, Google Interview Questions Upvote 0 Downvote
if not exists (select * from table where key ='somevalues here') insert table select <values> Denis The SQL Menace -------------------- SQL Server Code,Tips and Tricks, Performance Tuning SQLBlog.com, Google Interview Questions
Jun 22, 2007 Thread starter #4 jms493 MIS Joined May 16, 2007 Messages 11 Location US Beautiful Dennis.....Stored procedure created and job created to run every month. Thanks for the help guys. People will think I am actually smart today! Upvote 0 Downvote
Beautiful Dennis.....Stored procedure created and job created to run every month. Thanks for the help guys. People will think I am actually smart today!