title: Procedure or function !!! has too many arguments specified
body: <p>I am developing my very first stored procedure in SQL Server 2008 and need advice concerning the errors message.</p>
  
  <blockquote>
    <p>Procedure or function  xxx too many arguments specified</p>
  </blockquote>
  
  <p>which I get after executing the stored procedure <code>[dbo].[M_UPDATES]</code> that calls another stored procedure called <code>etl_M_Update_Promo</code>.</p>
  
  <p>When calling <code>[dbo].[M_UPDATES]</code> (code see below) via right-mouse-click and ‘Execute stored procedure’ the query that appears in the query-window is:</p>
  
  <pre><code>USE [Database_Test]
  GO
  
  DECLARE @return_value int
  
  EXEC    @return_value = [dbo].[M_UPDATES]
  
  SELECT  'Return Value' = @return_value
  
  GO
  </code></pre>
  
  <p>The output is </p>
  
  <blockquote>
    <p>Msg 8144, Level 16, State 2, Procedure etl_M_Update_Promo, Line 0<br>
    Procedure or function etl_M_Update_Promo has too many arguments specified.</p>
  </blockquote>
  
  <p><strong>QUESTION</strong>: What does this error message exactly mean, i.e. where are too many arguments? How to identify them?</p>
  
  <p>I found several threads asking about this error message, but the codes provided were all different to mine (if not in another language like <code>C#</code> anyway). So none of the answers solved the problem of my <code>SQL</code> query (i.e. SPs).</p>
  
  <p>Note: below I provide the code used for the two SPs, but I changed the database names, table names and column names. So, please, don’t be concerned about naming conventions, these are only example names!</p>
  
  <p>(1) Code for SP1 [dbo].[M_UPDATES]</p>
  
  <pre><code>USE [Database_Test]
  GO
  
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER PROCEDURE [dbo].[ M_UPDATES] AS
  declare @GenID bigint
  declare @Description nvarchar(50)
  
  Set @GenID = SCOPE_IDENTITY()
  Set @Description = 'M Update'
  
  BEGIN
  EXEC etl.etl_M_Update_Promo @GenID, @Description
  END
  
  GO
  </code></pre>
  
  <p>(2) Code for SP2  [etl_M_Update_Promo]</p>
  
  <pre><code>USE [Database_Test]
  GO
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER PROCEDURE [etl].[etl_M_Update_Promo]
  @GenId bigint = 0
  as
  
  declare @start datetime = getdate ()
  declare @Process varchar (100) = 'Update_Promo'
  declare @SummeryOfTable TABLE (Change varchar (20))
  declare @Description nvarchar(50)
  declare @ErrorNo int
  , @ErrorMsg varchar (max)
  declare @Inserts int = 0
  , @Updates int = 0
  , @Deleted int = 0
  , @OwnGenId bit = 0
  
  begin try
  
  
  if @GenId = 0 begin
  INSERT INTO Logging.dbo.ETL_Gen (Starttime)
  VALUES (@start)
  
  SET @GenId = SCOPE_IDENTITY()
  SET @OwnGenId = 1
  end
  
  
  MERGE [Database_Test].[dbo].[Promo] AS TARGET
  USING OPENQUERY( M ,'select * from m.PROMO' ) AS SOURCE 
  ON (TARGET.[E] = SOURCE.[E]) 
  
  
  WHEN MATCHED AND  TARGET.[A] &lt;&gt; SOURCE.[A]
    OR TARGET.[B] &lt;&gt; SOURCE.[B]
    OR TARGET.[C] &lt;&gt; SOURCE.[C]
    THEN 
  UPDATE SET TARGET.[A] = SOURCE.[A]
    ,TARGET.[B] = SOURCE.[B]
    , TARGET.[C] = SOURCE.[c]
  
  WHEN NOT MATCHED BY TARGET THEN 
  INSERT ([E]
    ,[A]
    ,[B]
    ,[C]
    ,[D]
    ,[F]
    ,[G]
    ,[H]
    ,[I]
    ,[J]
    ,[K]
    ,[L]  
    ) 
  VALUES (SOURCE.[E]
    ,SOURCE.[A]
    ,SOURCE.[B]
    ,SOURCE.[C]
    ,SOURCE.[D]
    ,SOURCE.[F]
    ,SOURCE.[G]
    ,SOURCE.[H]
    ,SOURCE.[I]
    ,SOURCE.[J]
    ,SOURCE.[K]
    ,SOURCE.[L]
  )
  
  OUTPUT $ACTION  INTO @SummeryOfTable; 
  
  
  with cte as (
  SELECT
  Change,
  COUNT(*) AS CountPerChange
  FROM @SummeryOfTable
  GROUP BY Change
  )
  
  SELECT
  @Inserts =
      CASE Change
          WHEN 'INSERT' THEN CountPerChange ELSE @Inserts
      END,
  @Updates =
      CASE Change
          WHEN 'UPDATE' THEN CountPerChange ELSE @Updates
      END,
  @Deleted =
      CASE Change
          WHEN 'DELETE' THEN CountPerChange ELSE @Deleted
      END
  FROM cte
  
  
  INSERT INTO Logging.dbo.ETL_log (GenID, Startdate, Enddate, Process, Message, Inserts, Updates, Deleted,Description)
  VALUES (@GenId, @start, GETDATE(), @Process, 'ETL succeded', @Inserts, @Updates,     @Deleted,@Description)
  
  
  if @OwnGenId = 1
  UPDATE Logging.dbo.ETL_Gen
  SET Endtime = GETDATE()
  WHERE ID = @GenId
  
  end try
  begin catch
  
  SET @ErrorNo = ERROR_NUMBER()
  SET @ErrorMsg = ERROR_MESSAGE()
  
  INSERT INTO Logging.dbo.ETL_Log (GenId, Startdate, Enddate, Process, Message, ErrorNo, Description)
  VALUES (@GenId, @start, GETDATE(), @Process, @ErrorMsg, @ErrorNo,@Description)
  
  
  end catch
  GO
  </code></pre>