title: SQL Server MERGE syntax unknown issue
body: <p>I really don't know what is wrong with my procedure, does anyone understand the issue?</p>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Procedure merge_table_from_json, Line 19 [Batch Start Line 0]<br>
    Incorrect syntax near 'tgt'</p>
  </blockquote>
  
  <p>My code:</p>
  
  <pre><code>ALTER PROCEDURE merge_table_from_json
      (@json nvarchar(max))
  AS
  BEGIN
      --  Delete From dbo.ExpensesScratch;
      --  Insert Into dbo.ExpensesScratch
      --  SELECT Id, Amount, StudentName 
      --  FROM OPENJSON(@json)
      --
      --  WITH (Id uniqueidentifier,
      --        Amount real, 
      --        StudentName NVARCHAR(50))
  
      MERGE dbo.Expenses AS tgt 
      USING dbo.ExpensesScratch AS src ON (tgt.Id = src.Id)
  
      WHEN MATCHED THEN 
          UPDATE SET tgt.Amount = src.Amount, 
                     tgt.StudentName = src.StudentName
  
      WHEN NOT MATCHED by tgt THEN
          INSERT (Id, Amount, StudentName) 
          VALUES (src.Id, src.Amount, src.StudentName)
  
      WHEN NOT MATCHED by src THEN 
          DELETE;  
  
      -- OUTPUT section,
      -- DELETED.Id AS tgtId,
      -- DELETED.StudentName AS tgtSudentName.
      -- DELETED.Amount AS tgtAmount,
      -- INSERTED.Id AS srcId,
      -- INSERTED.StudentName AS srcStudentName,
      -- INSERTED.Amount AS srcAmount
  
      SELECT @@ROWCOUNT
  END
  </code></pre>