How do I do batch upserts in SQL Server?
I'm using the MERGE statement to upsert rows in an sql server 2008 database. However, my sproc is a single-row operation, whereas in fact I'd prefer to batch these. Is this even possible and, if so, how do I do it? Can you use Table-Valued Parameters in your proc? Take a look here http://www.sommarskog.se/arrays-in-sql-2008.html#TVP_in_TSQL to get some ideas Then in the proc you can use MERGE against the TVP i have created a proc called 'upsert' which takes a source table name, target table name, fields to join on, and fields to update (fields are separated by commas) and then does the merge