SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Use Merge function but don't insert
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jamesbrummel
Starting Member

5 Posts

Posted - 01/08/2013 :  13:20:18  Show Profile  Reply with Quote
I'd like to use MERGE to get a list of non-matched records, but I don't want to insert them into the target table.

I can use OUTPUT to insert the non matches to a @table, but can't seem to prevent MERGE from INSERTING, I don't want to take any action other than to insert non matches into @table.

Thanks!!!

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 01/08/2013 :  13:33:18  Show Profile  Visit webfred's Homepage  Reply with Quote
then you should insert non matches into @table without merge and that output stuff...


Too old to Rock'n'Roll too young to die.
Go to Top of Page

jamesbrummel
Starting Member

5 Posts

Posted - 01/08/2013 :  14:17:28  Show Profile  Reply with Quote
I am trying to use the comparison that occurs in the MERGE function
under the assumption it will be faster than a field by field comparison of each row which I can code. My experience has been that built in SQL functions are much faster than anything I can code.

Is this not the case here,maybe? I would assume this would be common practice if there is a substantial performance gain over a proc.
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 01/08/2013 :  15:38:40  Show Profile  Reply with Quote
I'm not following your logic; a Merge statement still requires you to do the comparison of the columns you want to evaluate equality/inequality against (unless you did a checksum comparison or something). Additionally, a Merge statement can be used by itself (ad-hoc) or in a procedure. So, comparing it to a stored procedure doesn't really have any meaning.
Go to Top of Page

jamesbrummel
Starting Member

5 Posts

Posted - 01/10/2013 :  11:40:35  Show Profile  Reply with Quote
ahh, I think I see what you mean. In the MERGE I have to explicitly state ON colA=ColB, colC=ColD, etc.
essentially doing a bunch of JOINS on cols I list in the ON clause. I foolishly thought there was some more sophisticated comparing going on in the background based on the selection of fields in the USING clause. Nuts.

I haven't used it much, thought it might be faster than JOINS or UNION for comparing fields. I have a hunch it aint, it just looks like a gussied up JOIN, at least as far as comparing cols.

Thanks!

Most people who drown do so in chest deep water.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000