<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Merge Operations &#8211; Insert, Update, Delete in Single Execution</title>
	<atom:link href="http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/</link>
	<description>SQL, SQL Server, MySQL, Big Data and NoSQL</description>
	<lastBuildDate>Wed, 19 Jun 2013 21:45:15 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: SQL SERVER &#8211; Weekly Series &#8211; Memory Lane &#8211; #032 &#124; Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-492136</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; Weekly Series &#8211; Memory Lane &#8211; #032 &#124; Journey to SQL Authority with Pinal Dave]]></dc:creator>
		<pubDate>Sat, 08 Jun 2013 01:32:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-492136</guid>
		<description><![CDATA[[&#8230;] Merge Operations – Insert, Update, Delete in Single Execution MERGE is a new feature that provides an efficient way to do multiple DML operations. In earlier versions of SQL Server, we had to write separate statements to INSERT, UPDATE, or DELETE data based on certain conditions; however, at present, by using the MERGE statement, we can include the logic of such data changes in one statement that even checks when the data is matched and then just update it, and similarly, when the data is unmatched, it is inserted. [&#8230;]]]></description>
		<content:encoded><![CDATA[<p>[&#8230;] Merge Operations – Insert, Update, Delete in Single Execution MERGE is a new feature that provides an efficient way to do multiple DML operations. In earlier versions of SQL Server, we had to write separate statements to INSERT, UPDATE, or DELETE data based on certain conditions; however, at present, by using the MERGE statement, we can include the logic of such data changes in one statement that even checks when the data is matched and then just update it, and similarly, when the data is unmatched, it is inserted. [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raj</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-480411</link>
		<dc:creator><![CDATA[Raj]]></dc:creator>
		<pubDate>Wed, 22 May 2013 10:11:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-480411</guid>
		<description><![CDATA[Hi Pinal,

I want to understand, when we do this for millions of records as insert, which is suggestable to to use whether SSIS OLEDB destination or SQLServer MERGE Command?]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>I want to understand, when we do this for millions of records as insert, which is suggestable to to use whether SSIS OLEDB destination or SQLServer MERGE Command?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-373699</link>
		<dc:creator><![CDATA[Sam]]></dc:creator>
		<pubDate>Tue, 13 Nov 2012 22:17:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-373699</guid>
		<description><![CDATA[Ever get an answer on this?

Thanks!]]></description>
		<content:encoded><![CDATA[<p>Ever get an answer on this?</p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karthik</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-367319</link>
		<dc:creator><![CDATA[Karthik]]></dc:creator>
		<pubDate>Thu, 01 Nov 2012 03:51:03 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-367319</guid>
		<description><![CDATA[SQL SELECT Statement
This query is used to select certain columns of certain records from one or more database tables.

SELECT * from emp


selects all the fields of all the records from the table named &#039;emp&#039;

SELECT empno, ename from emp


selects the fields empno and ename of all the records from the table named &#039;emp&#039;

SELECT * from emp where empno &lt; 100


selects all those records from the table named &#039;emp&#039; where the value of the field empno is less than 100

SELECT * from article, author where article.authorId = author.authorId


selects all those records from the tables named &#039;article&#039; and &#039;author&#039; that have the same value of the field authorId

SQL INSERT Statement
This query is used to insert a record into a database table.

INSERT INTO emp(empno, ename) values(101, &#039;John Guttag&#039;)


inserts a record in to the emp table and set its empno field to 101 and its ename field to &#039;John Guttag&#039;

SQL UPDATE Statement
This query is used to modify existing records in a database table.

UPDATE emp SET ename = &#039;Eric Gamma&#039; WHERE empno = 101


updates the record whose empno field is 101 by setting its ename field to &#039;Eric Gamma&#039;

SQL DELETE Statement
This query is used to delete existing record(s) from a database table.

DELETE FROM emp WHERE empno = 101]]></description>
		<content:encoded><![CDATA[<p>SQL SELECT Statement<br />
This query is used to select certain columns of certain records from one or more database tables.</p>
<p>SELECT * from emp</p>
<p>selects all the fields of all the records from the table named &#8216;emp&#8217;</p>
<p>SELECT empno, ename from emp</p>
<p>selects the fields empno and ename of all the records from the table named &#8216;emp&#8217;</p>
<p>SELECT * from emp where empno &lt; 100</p>
<p>selects all those records from the table named &#039;emp&#039; where the value of the field empno is less than 100</p>
<p>SELECT * from article, author where article.authorId = author.authorId</p>
<p>selects all those records from the tables named &#039;article&#039; and &#039;author&#039; that have the same value of the field authorId</p>
<p>SQL INSERT Statement<br />
This query is used to insert a record into a database table.</p>
<p>INSERT INTO emp(empno, ename) values(101, &#039;John Guttag&#039;)</p>
<p>inserts a record in to the emp table and set its empno field to 101 and its ename field to &#039;John Guttag&#039;</p>
<p>SQL UPDATE Statement<br />
This query is used to modify existing records in a database table.</p>
<p>UPDATE emp SET ename = &#039;Eric Gamma&#039; WHERE empno = 101</p>
<p>updates the record whose empno field is 101 by setting its ename field to &#039;Eric Gamma&#039;</p>
<p>SQL DELETE Statement<br />
This query is used to delete existing record(s) from a database table.</p>
<p>DELETE FROM emp WHERE empno = 101</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vinod</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-351316</link>
		<dc:creator><![CDATA[Vinod]]></dc:creator>
		<pubDate>Thu, 20 Sep 2012 11:30:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-351316</guid>
		<description><![CDATA[Good alternative to doing the same on SSIS.
I was wondering how does the performance affect for the two Tables being on different Database/Servers?]]></description>
		<content:encoded><![CDATA[<p>Good alternative to doing the same on SSIS.<br />
I was wondering how does the performance affect for the two Tables being on different Database/Servers?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hari</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-321615</link>
		<dc:creator><![CDATA[hari]]></dc:creator>
		<pubDate>Mon, 30 Jul 2012 05:40:44 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-321615</guid>
		<description><![CDATA[IS THIS POSSIBLE TO CREATE INSERT, UPDATE AND DELETE IN A SINGLE TRIGGER?]]></description>
		<content:encoded><![CDATA[<p>IS THIS POSSIBLE TO CREATE INSERT, UPDATE AND DELETE IN A SINGLE TRIGGER?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aficionado</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-292253</link>
		<dc:creator><![CDATA[aficionado]]></dc:creator>
		<pubDate>Fri, 01 Jun 2012 12:11:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-292253</guid>
		<description><![CDATA[I am using a Stored procedure with merge statement.How i can get the number of rows inserted/Updated from the stored proc??]]></description>
		<content:encoded><![CDATA[<p>I am using a Stored procedure with merge statement.How i can get the number of rows inserted/Updated from the stored proc??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roger Keulen</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-262571</link>
		<dc:creator><![CDATA[Roger Keulen]]></dc:creator>
		<pubDate>Tue, 13 Mar 2012 15:11:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-262571</guid>
		<description><![CDATA[Nice, work....

To bad i have to use this [word removed] at my work.... not very professional....

I hope a lot of companies will download just a free Db ... that use this [word removed]...]]></description>
		<content:encoded><![CDATA[<p>Nice, work&#8230;.</p>
<p>To bad i have to use this [word removed] at my work&#8230;. not very professional&#8230;.</p>
<p>I hope a lot of companies will download just a free Db &#8230; that use this [word removed]&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hiteshagja</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-261119</link>
		<dc:creator><![CDATA[hiteshagja]]></dc:creator>
		<pubDate>Fri, 09 Mar 2012 14:35:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-261119</guid>
		<description><![CDATA[Hello,

I have used Merge statement for insert update in my stored procedure but I stuck upon one problem. How can I insert identity column in insert statement. 

Here is my query for your reference:

MERGE [dbo].[tReserveData_4541] AS Target
			USING (SELECT * FROM  [dbo].[tblcangrowhitesh]) AS Source
			ON ( [Source].[PK_ID] =  [Target].[PK_ID])
			WHEN MATCHED THEN
			UPDATE SET [Target].[mgender] = Source.[mgender]
			WHEN NOT MATCHED BY TARGET THEN
			INSERT ([PK_ID],[Granularity],[ROWID],[mgender],[mma1],[mma2],[mma3],[mmadmincost],[mmcumulativevolume],[mmcurrency],[mmdate],[mmfileimporteddate],[mmfilename])
			VALUES ([Source].[PK_ID],[Source].[Granularity],[Source].[ROWID],[Source].[mgender],[Source].[mma1],[Source].[mma2],[Source].[mma3],[Source].[mmadmincost],[Source].[mmcumulativevolume],[Source].[mmcurrency],[Source].[mmdate],[Source].[mmfileimporteddate],[Source].[mmfilename])


As you can see I am going to insert identity column [PK_ID] in merge-insert statement. But I am unable to do so. 

Please guide me!

Thanks,
Hitesh]]></description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I have used Merge statement for insert update in my stored procedure but I stuck upon one problem. How can I insert identity column in insert statement. </p>
<p>Here is my query for your reference:</p>
<p>MERGE [dbo].[tReserveData_4541] AS Target<br />
			USING (SELECT * FROM  [dbo].[tblcangrowhitesh]) AS Source<br />
			ON ( [Source].[PK_ID] =  [Target].[PK_ID])<br />
			WHEN MATCHED THEN<br />
			UPDATE SET [Target].[mgender] = Source.[mgender]<br />
			WHEN NOT MATCHED BY TARGET THEN<br />
			INSERT ([PK_ID],[Granularity],[ROWID],[mgender],[mma1],[mma2],[mma3],[mmadmincost],[mmcumulativevolume],[mmcurrency],[mmdate],[mmfileimporteddate],[mmfilename])<br />
			VALUES ([Source].[PK_ID],[Source].[Granularity],[Source].[ROWID],[Source].[mgender],[Source].[mma1],[Source].[mma2],[Source].[mma3],[Source].[mmadmincost],[Source].[mmcumulativevolume],[Source].[mmcurrency],[Source].[mmdate],[Source].[mmfileimporteddate],[Source].[mmfilename])</p>
<p>As you can see I am going to insert identity column [PK_ID] in merge-insert statement. But I am unable to do so. </p>
<p>Please guide me!</p>
<p>Thanks,<br />
Hitesh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Saravan</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-249323</link>
		<dc:creator><![CDATA[Saravan]]></dc:creator>
		<pubDate>Tue, 07 Feb 2012 04:24:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-249323</guid>
		<description><![CDATA[Hi,

In one of our application, we do lot of delete and insert to avoid Update (in Transaction tables). This delete and insert happens in threads. If we use Merge, will it lock table and cause timeout? Please suggest

Thanks.]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>In one of our application, we do lot of delete and insert to avoid Update (in Transaction tables). This delete and insert happens in threads. If we use Merge, will it lock table and cause timeout? Please suggest</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER &#8211; MERGE or INSERT, UPDATE, DELETE &#8211; Quiz &#8211; Puzzle &#8211; 19 of 31 &#171; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-241045</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; MERGE or INSERT, UPDATE, DELETE &#8211; Quiz &#8211; Puzzle &#8211; 19 of 31 &#171; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Fri, 20 Jan 2012 01:30:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-241045</guid>
		<description><![CDATA[[...] Server Interview Questions and Answers ISBN: 1466405643 Page#112 Merge Operations – Insert, Update, Delete in Single Execution Introduction to Merge Statement – One Statement for INSERT, UPDATE, DELETE Explanation SQL SERVER [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Server Interview Questions and Answers ISBN: 1466405643 Page#112 Merge Operations – Insert, Update, Delete in Single Execution Introduction to Merge Statement – One Statement for INSERT, UPDATE, DELETE Explanation SQL SERVER [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pranav</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-221798</link>
		<dc:creator><![CDATA[pranav]]></dc:creator>
		<pubDate>Tue, 20 Dec 2011 03:50:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-221798</guid>
		<description><![CDATA[when i merge more then 10000 record with original table,merge take lot of time time to complete process  please give solution for that]]></description>
		<content:encoded><![CDATA[<p>when i merge more then 10000 record with original table,merge take lot of time time to complete process  please give solution for that</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Slana</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-216026</link>
		<dc:creator><![CDATA[Peter Slana]]></dc:creator>
		<pubDate>Mon, 12 Dec 2011 12:26:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-216026</guid>
		<description><![CDATA[I found out that on the target table, when merge on large amount of records, the corresponding after trigger is fired only once. Although the data is populated in the target trigger (which means that the trigger should have been executed ok).
My after trigger executes some insert statements on other tables (mainly for somekind of logging).
I checked it using print statements after getting data from the inserted and deleted record (in case of after update trigger):
select @old_date = date1, @old_id = fkid from deleted;
select @new_date = date1, @new_id = fkid from inserted;
print &#039;my trigger started id old&#039; + str(@new_id)
print cast(@old_date as char)
print cast(@new_date as char)
---- some other statements follow.
Please help. Urgent.
thx]]></description>
		<content:encoded><![CDATA[<p>I found out that on the target table, when merge on large amount of records, the corresponding after trigger is fired only once. Although the data is populated in the target trigger (which means that the trigger should have been executed ok).<br />
My after trigger executes some insert statements on other tables (mainly for somekind of logging).<br />
I checked it using print statements after getting data from the inserted and deleted record (in case of after update trigger):<br />
select @old_date = date1, @old_id = fkid from deleted;<br />
select @new_date = date1, @new_id = fkid from inserted;<br />
print &#8216;my trigger started id old&#8217; + str(@new_id)<br />
print cast(@old_date as char)<br />
print cast(@new_date as char)<br />
&#8212;- some other statements follow.<br />
Please help. Urgent.<br />
thx</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Slana</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-215880</link>
		<dc:creator><![CDATA[Peter Slana]]></dc:creator>
		<pubDate>Mon, 12 Dec 2011 07:49:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-215880</guid>
		<description><![CDATA[Sorry the when not matched lines are (a little tipo while adding post):
WHEN NOT matched BY target AND EXISTS(SELECT p.id FROM dbo.Podjetja p WHERE p.ds = ‘si’ + s.davcna)]]></description>
		<content:encoded><![CDATA[<p>Sorry the when not matched lines are (a little tipo while adding post):<br />
WHEN NOT matched BY target AND EXISTS(SELECT p.id FROM dbo.Podjetja p WHERE p.ds = ‘si’ + s.davcna)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Slana</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-215877</link>
		<dc:creator><![CDATA[Peter Slana]]></dc:creator>
		<pubDate>Mon, 12 Dec 2011 07:47:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-215877</guid>
		<description><![CDATA[Hi.
I have a problem with merge and after insert trigger on target table.
I have the following not matched block:
WHEN NOT matched BY target AND EXISTS(SELECT p.id FROM dbo.Podjetja p WHERE p.ds = &#039;si&#039; + t.davcna) 
THEN 
    INSERT (podjetje_id, trr, datum_odprtja, datum_zaprtja, zaprt, rez, datum_spr, tip_id)
    VALUES ((SELECT TOP 1 p.id FROM dbo.Podjetja p WHERE p.ds = &#039;si&#039; + s.davcna), 
            s.trr, s.dOdprt, s.dZaprt, 
            CASE s.sSpre 
                WHEN &#039;Z&#039; THEN 1 
                ELSE 0 
            END,
            CASE s.eno
                WHEN NULL THEN 0
                ELSE 1
            END, s.dSpre, s.vr);
The after insert trigger is called and the inserted record is empty. Actually the not matched addition condition (exists) should not be called at all.

Is there a way to insert to the target with subqueries?

thx in advance]]></description>
		<content:encoded><![CDATA[<p>Hi.<br />
I have a problem with merge and after insert trigger on target table.<br />
I have the following not matched block:<br />
WHEN NOT matched BY target AND EXISTS(SELECT p.id FROM dbo.Podjetja p WHERE p.ds = &#8216;si&#8217; + t.davcna)<br />
THEN<br />
    INSERT (podjetje_id, trr, datum_odprtja, datum_zaprtja, zaprt, rez, datum_spr, tip_id)<br />
    VALUES ((SELECT TOP 1 p.id FROM dbo.Podjetja p WHERE p.ds = &#8216;si&#8217; + s.davcna),<br />
            s.trr, s.dOdprt, s.dZaprt,<br />
            CASE s.sSpre<br />
                WHEN &#8216;Z&#8217; THEN 1<br />
                ELSE 0<br />
            END,<br />
            CASE s.eno<br />
                WHEN NULL THEN 0<br />
                ELSE 1<br />
            END, s.dSpre, s.vr);<br />
The after insert trigger is called and the inserted record is empty. Actually the not matched addition condition (exists) should not be called at all.</p>
<p>Is there a way to insert to the target with subqueries?</p>
<p>thx in advance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-212955</link>
		<dc:creator><![CDATA[Joe]]></dc:creator>
		<pubDate>Wed, 07 Dec 2011 20:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-212955</guid>
		<description><![CDATA[hello,

I want to know if it this is possible:  data is written to table &#039;1&#039;, I would like this to trigger an insert statement on table &#039;2&#039;.  Using the below statement I created a trigger that will update values in table &#039;2&#039; from table &#039;1&#039;.  But this only seems to work if the entries already exist in each table and I am updated data.

Create trigger [dbo].[updatename] on [dbo].[table1]
for update
as

IF update (name)
begin
	declare @name varchar(20)
	select @name = (select isnull(name,&#039;&#039;)from inserted)
	update TABLE2
	set TABLE2.name = @name
	from TABLE2, inserted
	where TABLE2.ID = inserted.ID
end
GO  

Thanks!]]></description>
		<content:encoded><![CDATA[<p>hello,</p>
<p>I want to know if it this is possible:  data is written to table &#8217;1&#8242;, I would like this to trigger an insert statement on table &#8217;2&#8242;.  Using the below statement I created a trigger that will update values in table &#8217;2&#8242; from table &#8217;1&#8242;.  But this only seems to work if the entries already exist in each table and I am updated data.</p>
<p>Create trigger [dbo].[updatename] on [dbo].[table1]<br />
for update<br />
as</p>
<p>IF update (name)<br />
begin<br />
	declare @name varchar(20)<br />
	select @name = (select isnull(name,&#8221;)from inserted)<br />
	update TABLE2<br />
	set TABLE2.name = @name<br />
	from TABLE2, inserted<br />
	where TABLE2.ID = inserted.ID<br />
end<br />
GO  </p>
<p>Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elvis</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-212407</link>
		<dc:creator><![CDATA[Elvis]]></dc:creator>
		<pubDate>Wed, 07 Dec 2011 00:15:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-212407</guid>
		<description><![CDATA[Sorry I misread the &quot;2005&quot; as 2008. There is no merge feature in 2005. You will have to come up with some creative DML logic.]]></description>
		<content:encoded><![CDATA[<p>Sorry I misread the &#8220;2005&#8243; as 2008. There is no merge feature in 2005. You will have to come up with some creative DML logic.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elvis</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-212405</link>
		<dc:creator><![CDATA[Elvis]]></dc:creator>
		<pubDate>Wed, 07 Dec 2011 00:13:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-212405</guid>
		<description><![CDATA[if you&#039;re talking about remote databases on linked servers, or a different database on the same server, you need to create a select statement and use that as a derived table for the source. 
For example,

MERGE ThisDatabase.dbo.Student AS TargetTable
USING (SELECT StudentID, FirstName, LastName FROM LinkedServer.OtherDatabase.dbo.Student) AS SourceTable
ON TargetTable.StudentID = SourceTable.StudentID]]></description>
		<content:encoded><![CDATA[<p>if you&#8217;re talking about remote databases on linked servers, or a different database on the same server, you need to create a select statement and use that as a derived table for the source.<br />
For example,</p>
<p>MERGE ThisDatabase.dbo.Student AS TargetTable<br />
USING (SELECT StudentID, FirstName, LastName FROM LinkedServer.OtherDatabase.dbo.Student) AS SourceTable<br />
ON TargetTable.StudentID = SourceTable.StudentID</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elvis</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-212173</link>
		<dc:creator><![CDATA[Elvis]]></dc:creator>
		<pubDate>Tue, 06 Dec 2011 15:59:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-212173</guid>
		<description><![CDATA[I realized something from the example Pinal had. You can specify more than one WHEN MATCHED clauses, which means you can write a WHEN MATCHED AND srcTbl.col1  tgtTbl.col1 THEN... WHEN MATCHED AND srcTbl.col2  tgtTbl.col2 THEN... and so on....

Thanks for the lightbulb moment]]></description>
		<content:encoded><![CDATA[<p>I realized something from the example Pinal had. You can specify more than one WHEN MATCHED clauses, which means you can write a WHEN MATCHED AND srcTbl.col1  tgtTbl.col1 THEN&#8230; WHEN MATCHED AND srcTbl.col2  tgtTbl.col2 THEN&#8230; and so on&#8230;.</p>
<p>Thanks for the lightbulb moment</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AMIT</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-204195</link>
		<dc:creator><![CDATA[AMIT]]></dc:creator>
		<pubDate>Fri, 25 Nov 2011 07:34:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-204195</guid>
		<description><![CDATA[HOW CAN WE MERGE TWO DATABASE IN SINGLE DATABASE IN SQL 2005..........PLZ PROVIDE SOME HELP ...........]]></description>
		<content:encoded><![CDATA[<p>HOW CAN WE MERGE TWO DATABASE IN SINGLE DATABASE IN SQL 2005&#8230;&#8230;&#8230;.PLZ PROVIDE SOME HELP &#8230;&#8230;&#8230;..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yaroslav</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-190198</link>
		<dc:creator><![CDATA[Yaroslav]]></dc:creator>
		<pubDate>Mon, 07 Nov 2011 16:03:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-190198</guid>
		<description><![CDATA[Great blog Pinal ! It has helped me a lot. One question. I&#039;m trying to find information on whether I can run upsert sentences affecting other tables instead of Target/Source ones inside the Merge query and I&#039;m still not sure if I can or not. I want to accomplish something like:

MERGE table1 AS stm
USING table2 AS sd
ON ID1=ID2
WHEN MATCHED BY TARGET THEN
DELETE table1
DELETE table3
WHEN NOT MATCHED THEN
INSERT(table1_field1,table1_field2)   --insert into table1
VALUES(11,12)
INSERT(table3_field1,table3_field2)  --insert into table3
VALUES(31,32);]]></description>
		<content:encoded><![CDATA[<p>Great blog Pinal ! It has helped me a lot. One question. I&#8217;m trying to find information on whether I can run upsert sentences affecting other tables instead of Target/Source ones inside the Merge query and I&#8217;m still not sure if I can or not. I want to accomplish something like:</p>
<p>MERGE table1 AS stm<br />
USING table2 AS sd<br />
ON ID1=ID2<br />
WHEN MATCHED BY TARGET THEN<br />
DELETE table1<br />
DELETE table3<br />
WHEN NOT MATCHED THEN<br />
INSERT(table1_field1,table1_field2)   &#8211;insert into table1<br />
VALUES(11,12)<br />
INSERT(table3_field1,table3_field2)  &#8211;insert into table3<br />
VALUES(31,32);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-182918</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Mon, 24 Oct 2011 14:09:25 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-182918</guid>
		<description><![CDATA[Note that Merge statement is introduced in version 2008. It will not work in earlier versions]]></description>
		<content:encoded><![CDATA[<p>Note that Merge statement is introduced in version 2008. It will not work in earlier versions</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vishal</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-182681</link>
		<dc:creator><![CDATA[vishal]]></dc:creator>
		<pubDate>Mon, 24 Oct 2011 07:11:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-182681</guid>
		<description><![CDATA[this command not working on sql server 2005.]]></description>
		<content:encoded><![CDATA[<p>this command not working on sql server 2005.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hadi</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-178774</link>
		<dc:creator><![CDATA[Hadi]]></dc:creator>
		<pubDate>Fri, 14 Oct 2011 11:20:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-178774</guid>
		<description><![CDATA[its very help full for me.awesome]]></description>
		<content:encoded><![CDATA[<p>its very help full for me.awesome</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blog.sqlauthority.com/2010/06/08/sql-server-merge-operations-insert-update-delete-in-single-execution/#comment-178531</link>
		<dc:creator><![CDATA[Doug]]></dc:creator>
		<pubDate>Thu, 13 Oct 2011 23:15:48 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=9195#comment-178531</guid>
		<description><![CDATA[can&#039;t you compare all columns in the when matched section to see if any have changed before doing update?  This would eliminate the update if nothing has changed.]]></description>
		<content:encoded><![CDATA[<p>can&#8217;t you compare all columns in the when matched section to see if any have changed before doing update?  This would eliminate the update if nothing has changed.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
