Copy table 1 to table 2 for missing data only
-
-
I have two tables that are identical, 1 table has old data and the other new data. I want to copy the old to the new where the records are either blank or null is there an easy way I can do this. Any help is appreciated. Thanks in advance, Michael
Which column is unique on both tables? Syntax is like this:
Insert into table2 (col1,col2,col3)
select col1,col2,col3 from table1In this select statement you have to include
where
clause with unique column in table1 and tale2
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.cacttus.com
-
I have two tables that are identical, 1 table has old data and the other new data. I want to copy the old to the new where the records are either blank or null is there an easy way I can do this. Any help is appreciated. Thanks in advance, Michael
Are they in the same database? Are they on the same server? Are they the same brand of database? When I had to copy data from an Ingres database on a Unix system to an SQL Server database on Windows there were times I had to simply throw the records at the database one by one and catch-log-and-ignore any duplicate Exceptions encountered. Simple but effective, and quicker than trying to test each record first.
-
Are they in the same database? Are they on the same server? Are they the same brand of database? When I had to copy data from an Ingres database on a Unix system to an SQL Server database on Windows there were times I had to simply throw the records at the database one by one and catch-log-and-ignore any duplicate Exceptions encountered. Simple but effective, and quicker than trying to test each record first.
They are in the same DB on the same server. I copy all the old records to a similar table Delete the orig table's records Start with a blank table, this is a starting point to build other info, I do not want many of the records from the old included which I do not know until I start new. Add new data Then I want to insert old data where new data is left blank and do not wish to overwrite new data. The previous response said the following: Insert into table2 (col1,col2,col3) select col1,col2,col3 from table1 I am thinking if I used the above then added Where col1 IS LIKE '' or col1 IS NULL but I would have to do this for every column, I was hoping there would be a quick easy way Michael
-
They are in the same DB on the same server. I copy all the old records to a similar table Delete the orig table's records Start with a blank table, this is a starting point to build other info, I do not want many of the records from the old included which I do not know until I start new. Add new data Then I want to insert old data where new data is left blank and do not wish to overwrite new data. The previous response said the following: Insert into table2 (col1,col2,col3) select col1,col2,col3 from table1 I am thinking if I used the above then added Where col1 IS LIKE '' or col1 IS NULL but I would have to do this for every column, I was hoping there would be a quick easy way Michael
-
I have two tables that are identical, 1 table has old data and the other new data. I want to copy the old to the new where the records are either blank or null is there an easy way I can do this. Any help is appreciated. Thanks in advance, Michael
SQL Server supports a rather convenient MERGE[^] command that lets you specify criteria of two records being 'identical', actions to take on finding a match, and actions to take on finding missing records. The documentation at the link supplies several large examples, so you should be able to construct your statement relatively easily.