On a User-Defined Table Type, @TT dbo.IntType readonly,,
IntType is batch of int, as Primary-Key
CREATE TYPE [dbo].[IntType] AS TABLE(
[T] [int] NOT NULL,
PRIMARY KEY CLUSTERED
I would like to do an UPDATE based on all key(int) in IntType, and INSERT new rows for the key(int) not exist in the database (an upsert). How?
I wonder if there is an easy way to remove the "UPDATED" key(int)? Then I can insert the rest.
(or if you have a super one-line upsert for SQL Server)
Use the
MERGEstatement.http://technet.microsoft.com/en-us/library/bb510625.aspx
Let me see if I can put something together.
EDIT: Example
EDIT 2: The parameter
@listis the list that is passed in that you populated with the ids