Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What I am trying to accomplish is having a reference/source table we will call (C) that the data gets inserted into after table (A) gets updated from Table (B)


update table A where table B.col1 = A.col1 and B.col2 = A.col2
Set A.col3= B.col3 and A.col4 = B.col4

insert into C (Source_ID, source_reference) where B.col1= A.col1 and B.col2 = A.col2

then delete matched sources from table B to get rid of duplicates.

What I have tried:

I have tried to use a match and merge statement, however, I cannot use a match merge statement to transfer to a source table for references later.
Posted
Updated 4-Aug-18 3:42am
v2
Comments
[no name] 3-Aug-18 17:56pm    
From where you learned this rubbish SQL update Statement like this (note the ??):

update table A where table B.col1 = A.col1 and B.col2 = A.col2
Set
A.col1= B.col1
?? and A.col2 = B.col2 ??
Member 11856456 4-Aug-18 9:43am    
Sorry, I realized after your question that I duplicated the columns. I have updated the question.
[no name] 4-Aug-18 9:54am    
No Need to be sorry. Anyway I don't see a big difference. From my Point of view you Need to fix first the update Statement:
update table A
Set A.col3= B.col3,
A.col4 = B.col4
where table B.col1 = A.col1 and B.col2 = A.col2
[no name] 4-Aug-18 10:48am    
Your question is (at least for me) very unclear. Apart from that your insert Statement is syntax wise wrong; it is completely unrelated to the Prior update...
Santosh kumar Pithani 4-Aug-18 0:57am    
why your using same columns "B.col1 = A.col1 and B.col2 = A.col2" for condition as well as update set?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900