I have about 170 tables that I need to update. Basically DB2 needs to be merged into DB1 and make sure not to create duplicate records. Ultimately it would be nice to be able to delete the records from DB2 and leave any duplicates in it so I can go back later and look at them to see why they were duplicates. ( but the deleting is secondary if even needed ) So I found this little script -- that i cannot seem to get workingI personally would not have made the column name Type. That's a previous developer.INSERT INTO DB1.DBO.AgencyCodes SELECT MDBN.* FROM DB2.DBO.AgencyCodes AS MDBN LEFT JOIN DB1.dbo.AgencyCodes AS ODBN ON ODBN.agency = MDBN.agency and odbn.[Type] = MDBN.[Type] and odbn.Code = mdbn.code WHERE odbn.agency is Null and odbn.[Type] is Null and odbn.Code is Null
Am I barking up the wrong tree? If not then why doesn't this seem to work? These are the errors I get when i try to run it:Msg 207, Level 16, State 1, Line 1Invalid column name 'Type'.Msg 207, Level 16, State 1, Line 1Invalid column name 'Type'.Msg 207, Level 16, State 1, Line 1Invalid column name 'Code'.Msg 207, Level 16, State 1, Line 1Invalid column name 'code'.Msg 207, Level 16, State 1, Line 1Invalid column name 'Type'.Msg 207, Level 16, State 1, Line 1Invalid column name 'Code'.
If it helps to know. I am updating a VB6 program to VB.NET. I will be running this SQL statement from withing the VB.NET program. In a nutshell: I have 2 db. I need to move the records from db2 into db1, they have the exact same schema. In the program I will be looping through each table and depending on other criteria move the records from db2 into db1. I am hoping to be able to do it with one SQL statement for each table.