title: SQL MERGE with variables
body: <p>How can I use the merge function with @variables in Microsoft SQL Server Management Studio 2008 r2? </p>
  
  <p>All of the examples that I have searched for online use tables to merge into tables. Is this possible with variables? </p>
  
  <p>For Example: </p>
  
  <pre><code>CREATE PROCEDURE UpdateOrder
              @id int,
              @payment_date smalldatetime,
              @amount numeric(10,2)
  
  AS
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
  
  
  
      MERGE order AS o
      USING @id, @payment_date, @amount
      ON @id = o.id
      WHEN MATCHED THEN 
                      UPDATE SET 
                                 o.payment_date = @payment_date,
                                 o.amount = @amount
                                 o.last_updated_on = GETDATE()
      WHEN NOT MATCHED THEN
          INSERT(o.id,o.payment_id,o.amount)
          VALUES(@id,@payment_id,@amount);
  </code></pre>
  
  <p>This does not work. Thanks!</p>