Hello, I have a datatable generate from an application. All rows in the table have the same vlaues in the second column.(Not Primary Key). I want to replace the rows in a database table in SQL server 2008 R2 which have the same column values.
That means: 1. If rows are not in the database table, insertion. 2. If rows are in the database table, updatation. 3. If rows are not in the new table but in Sql Server, deletion.
merge table1 t1 using table2 t2 on t1.id = t2.id when matched then update set colb = t2.colb when not matched by target then insert (id, colb) values (t2.id,t2.colb) when not matched by source then delete;
========================================== Cursors are useful if you don't know sql. SSIS can be used in a similar way. Beer is not cold and it isn't fizzy.