title: Using MERGE command with JSON data
body: <p>Is it possible to update a table directly using JSON, without inserting to a temp table?</p>
  
  <p>Below code inserts data to a temp table and updates the original table.</p>
  
  <pre><code>DECLARE @TempTelecommunicationsNumber AS TABLE (RoleID INT,Number VARCHAR(100),Ext VARCHAR(100))
  INSERT INTO @TempTelecommunicationsNumber (RoleID,Number,Ext)
   SELECT     @RoleID, Number,Ext
   FROM       OPENJSON(@TelecommunicationsNumber)
   WITH       (RoleID INT, Number NVARCHAR(256), Ext NVARCHAR(256))
  
              MERGE Party.TelecommunicationsNumber original
              USING @TempTelecommunicationsNumber modified
              ON (original.RoleID = modified.RoleID)
              WHEN MATCHED
                  THEN UPDATE SET
                  original.Number = modified.Number,
                  original.Ext = modified.Ext
              WHEN NOT MATCHED BY TARGET
                  THEN INSERT (RoleID,Number,Ext)
                  VALUES (@RoleID,modified.Number,modified.Ext);
  </code></pre>
  
  <p>Is there a way to update directly as below.</p>
  
  <pre><code>MERGE Party.TelecommunicationsNumber original
  USING OPENJSON(@Json) modified
  ON (original.RoleID = modified.RoleID)
  WHEN MATCHED
      THEN UPDATE SET
      original.Number = modified.Number,
      original.Ext = modified.Ext
  WHEN NOT MATCHED BY TARGET
      THEN INSERT (RoleID,Number,Ext)
      VALUES (@RoleID,modified.Number,modified.Ext);
  </code></pre>