Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-05-17 : 03:34:43
|
| Create Table #TableA (id int ,Fname nvarchar(23),Lname nvarchar(23))insert into #TableA Select 1,'Hi','India1' Union allSelect 2,'Think','India'Drop Table #TableBCreate Table #TableB (id int ,Fname nvarchar(23),Lname nvarchar(23))insert into #TableB Select 3,'Hello','What'Select 1,'Hi','India'Create Table #Temp (id int ,Fname nvarchar(23),Lname nvarchar(23))--This is Working FineSelect * From #TAbleASelect * from #TableBMerge #TableA As TAUsing (Select * from #TableB) As TBOn TA.id=TB.idWhen Matched ThenUpdate Set TA.Fname=TB.FnameWhen not Matched Then Insert (id,Fname,Lname) Values (TB.ID,TB.Fname,TB.Lname);Select * From #TableA--But This is not working Select * From #TAbleASelect * from #TableBMerge #TableA As TAUsing (Select * from #TableB) As TBOn TA.id=TB.idWhen Matched Then--No bigin and end not working Update #Temp Set (id,Fname,Lname)=(Tb.id,Tb.Fname,Tb.Lname)When not Matched Then Insert (id,Fname,Lname) Values (TB.ID,TB.Fname,TB.Lname);Select * From #TableAIn Love... With Me! |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2011-05-17 : 05:22:33
|
| What is your question? |
 |
|
|
raghuveer125
Constraint Violating Yak Guru
285 Posts |
Posted - 2011-05-17 : 07:18:15
|
| How can I move data to archive before updating to main table tableA. See i have tableA with some data and my second table tableB have some repeted data those are already in tableA now before I update tableA comparing to TableB I need to move tableA data to archiveIn Love... With Me! |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2011-05-17 : 10:03:50
|
| Easiest way in this case would probably be a trigger on the table. |
 |
|
|
|
|
|
|
|