Jason-299789 (11/7/2012)
Tava, you can insert the same record twice with a merge statement, heres a test rig.
Create Table #test_merge_target (
Col1 varchar(10)
,Col2 varchar(10)
)
Create Table #test_merge_source (
Col1 varchar(10)
,Col2 varchar(10)
)
Insert into #test_merge_source
values ('Acol','test data')
,('Acol','test data')
,('bcol','test data')
Merge into
#test_merge_target as target
USING #test_merge_source as Source
ON target.Col1=Source.Col1
WHEN MATCHED THEN
Update Set target.Col2=Source.Col2
When NOT MATCHED Then
INSERT (Col1,Col2)
VALUES (Source.Col1,Source.Col2);
Select * from #test_merge_target
GO
drop table #test_merge_source
drop table #test_merge_target
however you cannot UPDATE or DELETE the Same row twice.
one way to aviod this is to use unique condition for the rowset;
i.e if unique column exist then add that in the NOT MATCHED condition ...
~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one :ermm: