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 |
subhaoviya
Posting Yak Master
135 Posts |
Posted - 2012-08-28 : 07:55:21
|
Hi, I Have merge statement in my stored procedure, which has both Update and insert action. Is it possible to get the count of affected rows after this statement?my query Merge [Target] as TUsing [Source] as Son(S.C1=T.C1)When Matched thenUpdate setT.C2=S.C2When not matched by target theninsert (c1,c2)values(s.C1,S.C2) if 2 rows gets updated and 2 gets inserted in the above statement, i need 5 as count.ThanksSubha |
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-08-28 : 08:46:59
|
DECLARE @RowCount INTMerge [Target] as T Using [Source] as Son( S.C1 = T.C1 ) When Matched thenUpdateset T.C2 = S.C2 When not matched by target theninsert ( c1, c2 )values ( s.C1, S.C2 )SELECT @RowCount = @@ROWCOUNT--------------------------http://connectsql.blogspot.com/ |
|
|
|
|
|