Executing stored procedure one argument is too few, two is too many2019 Community Moderator ElectionSelect columns from result set of stored procedureProgrammatically retrieve SQL Server stored procedure source that is identical to the source returned by the SQL Server Management Studio gui?Insert results of a stored procedure into a temporary tableFunction vs. Stored Procedure in SQL ServerEntity Framework: no Primary key/can't execute Stored ProceduresSearch text in stored procedure in SQL ServerProcedure or function !!! has too many arguments specifiedstored procedure too many arguments errorGetting rows affected in stored procedure INSERT statement with NOCOUNT OFFStored procedure has too many arguments specified C#

Ban on all campaign finance?

Rejected in 4th interview round citing insufficient years of experience

PTIJ: Who should pay for Uber rides: the child or the parent?

How to make healing in an exploration game interesting

Force user to remove USB token

Does the statement `int val = (++i > ++j) ? ++i : ++j;` invoke undefined behavior?

The use of "touch" and "touch on" in context

How to explain that I do not want to visit a country due to personal safety concern?

Why would a flight no longer considered airworthy be redirected like this?

Define, (actually define) the "stability" and "energy" of a compound

Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?

Does this AnyDice function accurately calculate the number of ogres you make unconcious with three 4th-level castings of Sleep?

It's a yearly task, alright

Good allowance savings plan?

Importance of differentiation

Could the Saturn V actually have launched astronauts around Venus?

Informing my boss about remarks from a nasty colleague

2D counterpart of std::array in C++17

How to write cleanly even if my character uses expletive language?

Who is our nearest planetary neighbor, on average?

Life insurance that covers only simultaneous/dual deaths

Is having access to past exams cheating and, if yes, could it be proven just by a good grade?

Welcoming 2019 Pi day: How to draw the letter π?

When do we add an hyphen (-) to a complex adjective word?



Executing stored procedure one argument is too few, two is too many



2019 Community Moderator ElectionSelect columns from result set of stored procedureProgrammatically retrieve SQL Server stored procedure source that is identical to the source returned by the SQL Server Management Studio gui?Insert results of a stored procedure into a temporary tableFunction vs. Stored Procedure in SQL ServerEntity Framework: no Primary key/can't execute Stored ProceduresSearch text in stored procedure in SQL ServerProcedure or function !!! has too many arguments specifiedstored procedure too many arguments errorGetting rows affected in stored procedure INSERT statement with NOCOUNT OFFStored procedure has too many arguments specified C#










0















I have a procedure like this



SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[INSERT_MessageOwner]
@ownertype AS INT,
@ownertenant AS INT
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO ADMINROTAS.dbo.MessageOwner
OUTPUT Inserted.MessageOwnerID
VALUES (@ownertype, @ownertenant);
END


If I call that procedure like this:



DECLARE @messageOwnerType INT;
SET @messageOwnerType = 3;
...
EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType
...


I get




Procedure or function 'INSERT_MessageOwner' expects parameter '@ownertenant', which was not supplied.




If I call it like this:



DECLARE @messageOwnerType INT;
DECLARE @messageOwnerDB INT;
SET @messageOwnerType = 3;
SET @messageOwnerDB = DB_ID();
...

EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB
...


I get




Procedure or function INSERT_MessageOwner has too many arguments specified.




Does anyone know what is going on here? I guess it may be something to do with the OUTPUT clause, but I am having difficulty figuring it out or finding just the right teaching on it.



I would really appreciate it if someone could put me in the picture. Having said all this, is there something wrong with this error message? You left off an argument! Add one. Now you have too many!



As an additional, I would be really grateful if you could help me understand how to get the results of the stored procedure into a variable. This stored procedure has worked usefully in JDBC, but now I want to use it with T-SQL.



Thank you so much.










share|improve this question




























    0















    I have a procedure like this



    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    ALTER PROCEDURE [dbo].[INSERT_MessageOwner]
    @ownertype AS INT,
    @ownertenant AS INT
    AS
    BEGIN
    SET NOCOUNT ON;

    INSERT INTO ADMINROTAS.dbo.MessageOwner
    OUTPUT Inserted.MessageOwnerID
    VALUES (@ownertype, @ownertenant);
    END


    If I call that procedure like this:



    DECLARE @messageOwnerType INT;
    SET @messageOwnerType = 3;
    ...
    EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType
    ...


    I get




    Procedure or function 'INSERT_MessageOwner' expects parameter '@ownertenant', which was not supplied.




    If I call it like this:



    DECLARE @messageOwnerType INT;
    DECLARE @messageOwnerDB INT;
    SET @messageOwnerType = 3;
    SET @messageOwnerDB = DB_ID();
    ...

    EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB
    ...


    I get




    Procedure or function INSERT_MessageOwner has too many arguments specified.




    Does anyone know what is going on here? I guess it may be something to do with the OUTPUT clause, but I am having difficulty figuring it out or finding just the right teaching on it.



    I would really appreciate it if someone could put me in the picture. Having said all this, is there something wrong with this error message? You left off an argument! Add one. Now you have too many!



    As an additional, I would be really grateful if you could help me understand how to get the results of the stored procedure into a variable. This stored procedure has worked usefully in JDBC, but now I want to use it with T-SQL.



    Thank you so much.










    share|improve this question


























      0












      0








      0








      I have a procedure like this



      SET ANSI_NULLS ON
      GO
      SET QUOTED_IDENTIFIER ON
      GO

      ALTER PROCEDURE [dbo].[INSERT_MessageOwner]
      @ownertype AS INT,
      @ownertenant AS INT
      AS
      BEGIN
      SET NOCOUNT ON;

      INSERT INTO ADMINROTAS.dbo.MessageOwner
      OUTPUT Inserted.MessageOwnerID
      VALUES (@ownertype, @ownertenant);
      END


      If I call that procedure like this:



      DECLARE @messageOwnerType INT;
      SET @messageOwnerType = 3;
      ...
      EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType
      ...


      I get




      Procedure or function 'INSERT_MessageOwner' expects parameter '@ownertenant', which was not supplied.




      If I call it like this:



      DECLARE @messageOwnerType INT;
      DECLARE @messageOwnerDB INT;
      SET @messageOwnerType = 3;
      SET @messageOwnerDB = DB_ID();
      ...

      EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB
      ...


      I get




      Procedure or function INSERT_MessageOwner has too many arguments specified.




      Does anyone know what is going on here? I guess it may be something to do with the OUTPUT clause, but I am having difficulty figuring it out or finding just the right teaching on it.



      I would really appreciate it if someone could put me in the picture. Having said all this, is there something wrong with this error message? You left off an argument! Add one. Now you have too many!



      As an additional, I would be really grateful if you could help me understand how to get the results of the stored procedure into a variable. This stored procedure has worked usefully in JDBC, but now I want to use it with T-SQL.



      Thank you so much.










      share|improve this question
















      I have a procedure like this



      SET ANSI_NULLS ON
      GO
      SET QUOTED_IDENTIFIER ON
      GO

      ALTER PROCEDURE [dbo].[INSERT_MessageOwner]
      @ownertype AS INT,
      @ownertenant AS INT
      AS
      BEGIN
      SET NOCOUNT ON;

      INSERT INTO ADMINROTAS.dbo.MessageOwner
      OUTPUT Inserted.MessageOwnerID
      VALUES (@ownertype, @ownertenant);
      END


      If I call that procedure like this:



      DECLARE @messageOwnerType INT;
      SET @messageOwnerType = 3;
      ...
      EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType
      ...


      I get




      Procedure or function 'INSERT_MessageOwner' expects parameter '@ownertenant', which was not supplied.




      If I call it like this:



      DECLARE @messageOwnerType INT;
      DECLARE @messageOwnerDB INT;
      SET @messageOwnerType = 3;
      SET @messageOwnerDB = DB_ID();
      ...

      EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB
      ...


      I get




      Procedure or function INSERT_MessageOwner has too many arguments specified.




      Does anyone know what is going on here? I guess it may be something to do with the OUTPUT clause, but I am having difficulty figuring it out or finding just the right teaching on it.



      I would really appreciate it if someone could put me in the picture. Having said all this, is there something wrong with this error message? You left off an argument! Add one. Now you have too many!



      As an additional, I would be really grateful if you could help me understand how to get the results of the stored procedure into a variable. This stored procedure has worked usefully in JDBC, but now I want to use it with T-SQL.



      Thank you so much.







      tsql stored-procedures sql-server-2014






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 13:03









      marc_s

      581k13011211268




      581k13011211268










      asked Mar 7 at 12:44









      hardyahardya

      165




      165






















          2 Answers
          2






          active

          oldest

          votes


















          0














          few missing () and it's good policy to add your column names for insert



          ALTER PROCEDURE [dbo].[INSERT_MessageOwner] (
          @ownertype AS INT,
          @ownertenant AS INT
          )
          AS
          BEGIN
          SET NOCOUNT ON;

          INSERT INTO ADMINROTAS.dbo.MessageOwner (yourcolumn1, yourcolumn2)
          OUTPUT Inserted.MessageOwnerID
          VALUES (@ownertype, @ownertenant);
          END





          share|improve this answer
































            0














            I have no problem running this:



            CREATE DATABASE ADMINROTAS

            GO

            CREATE TABLE ADMINROTAS.dbo.MessageOwner
            (
            MessageOwnerID INT IDENTITY PRIMARY KEY,
            ownertype INT,
            ownertenant INT
            )

            GO

            SET ANSI_NULLS ON
            GO
            SET QUOTED_IDENTIFIER ON
            GO

            CREATE PROCEDURE [dbo].[INSERT_MessageOwner]
            @ownertype AS INT,
            @ownertenant AS INT
            AS
            BEGIN
            SET NOCOUNT ON;

            INSERT INTO ADMINROTAS.dbo.MessageOwner
            OUTPUT Inserted.MessageOwnerID
            VALUES (@ownertype, @ownertenant);
            END

            GO

            DECLARE @messageOwnerType INT;
            SET @messageOwnerType = 3;
            EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType

            GO

            DECLARE @messageOwnerType INT;
            DECLARE @messageOwnerDB INT;
            SET @messageOwnerType = 3;
            SET @messageOwnerDB = DB_ID();

            EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB


            Maybe you missed something when writing the question.
            I suppose that MessageOwnerID is the identity column of your table. To get this value, you first need to declare a table varible like @Temp with the structure of the column you want output from your insert:



            DECLARE @Temp TABLE
            (
            MessageOwnerID INT
            )


            Second, you need to change your OUTPUT statement to insert this result into the variable:



            OUTPUT Inserted.MessageOwnerID INTO @Temp


            You now have this results in your table. You can write a select statement at the end of your procedure, or because you are sure you are inserting only one record, you can declare a variable @MessageOwnerID let's say. In order to return this value to the caller, you have to declare it as OUTPUT parameter. Set it's value to the value from the temp table and read it on execute. Your procedure is modifying like this:



            ALTER PROCEDURE [dbo].[INSERT_MessageOwner]
            @ownertype AS INT,
            @ownertenant AS INT,
            @MessageOwnerID INT = NULL OUTPUT
            AS
            BEGIN
            SET NOCOUNT ON;

            DECLARE @Temp TABLE
            (
            MessageOwnerID INT
            )

            INSERT INTO ADMINROTAS.dbo.MessageOwner
            OUTPUT Inserted.MessageOwnerID INTO @Temp
            VALUES (@ownertype, @ownertenant);

            SELECT @MessageOwnerID = MessageOwnerID FROM @Temp
            END


            Remember the OUTPUT keyword on the parameter declaration!



            The call to the procedure changes to this:



            DECLARE @messageOwnerType INT;
            DECLARE @messageOwnerDB INT;
            DECLARE @MessageOwnerID INT;
            SET @messageOwnerType = 3;
            SET @messageOwnerDB = DB_ID();

            EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB, @MessageOwnerID = @MessageOwnerID OUTPUT
            SELECT @MessageOwnerID


            Also, remember the OUTPUT keyword on all and the key-value pair of parameter name and variable (you should always use this way to call procedures).



            Get a try and come back!






            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044112%2fexecuting-stored-procedure-one-argument-is-too-few-two-is-too-many%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              few missing () and it's good policy to add your column names for insert



              ALTER PROCEDURE [dbo].[INSERT_MessageOwner] (
              @ownertype AS INT,
              @ownertenant AS INT
              )
              AS
              BEGIN
              SET NOCOUNT ON;

              INSERT INTO ADMINROTAS.dbo.MessageOwner (yourcolumn1, yourcolumn2)
              OUTPUT Inserted.MessageOwnerID
              VALUES (@ownertype, @ownertenant);
              END





              share|improve this answer





























                0














                few missing () and it's good policy to add your column names for insert



                ALTER PROCEDURE [dbo].[INSERT_MessageOwner] (
                @ownertype AS INT,
                @ownertenant AS INT
                )
                AS
                BEGIN
                SET NOCOUNT ON;

                INSERT INTO ADMINROTAS.dbo.MessageOwner (yourcolumn1, yourcolumn2)
                OUTPUT Inserted.MessageOwnerID
                VALUES (@ownertype, @ownertenant);
                END





                share|improve this answer



























                  0












                  0








                  0







                  few missing () and it's good policy to add your column names for insert



                  ALTER PROCEDURE [dbo].[INSERT_MessageOwner] (
                  @ownertype AS INT,
                  @ownertenant AS INT
                  )
                  AS
                  BEGIN
                  SET NOCOUNT ON;

                  INSERT INTO ADMINROTAS.dbo.MessageOwner (yourcolumn1, yourcolumn2)
                  OUTPUT Inserted.MessageOwnerID
                  VALUES (@ownertype, @ownertenant);
                  END





                  share|improve this answer















                  few missing () and it's good policy to add your column names for insert



                  ALTER PROCEDURE [dbo].[INSERT_MessageOwner] (
                  @ownertype AS INT,
                  @ownertenant AS INT
                  )
                  AS
                  BEGIN
                  SET NOCOUNT ON;

                  INSERT INTO ADMINROTAS.dbo.MessageOwner (yourcolumn1, yourcolumn2)
                  OUTPUT Inserted.MessageOwnerID
                  VALUES (@ownertype, @ownertenant);
                  END






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 7 at 17:18

























                  answered Mar 7 at 17:07









                  JBJJBJ

                  1665




                  1665























                      0














                      I have no problem running this:



                      CREATE DATABASE ADMINROTAS

                      GO

                      CREATE TABLE ADMINROTAS.dbo.MessageOwner
                      (
                      MessageOwnerID INT IDENTITY PRIMARY KEY,
                      ownertype INT,
                      ownertenant INT
                      )

                      GO

                      SET ANSI_NULLS ON
                      GO
                      SET QUOTED_IDENTIFIER ON
                      GO

                      CREATE PROCEDURE [dbo].[INSERT_MessageOwner]
                      @ownertype AS INT,
                      @ownertenant AS INT
                      AS
                      BEGIN
                      SET NOCOUNT ON;

                      INSERT INTO ADMINROTAS.dbo.MessageOwner
                      OUTPUT Inserted.MessageOwnerID
                      VALUES (@ownertype, @ownertenant);
                      END

                      GO

                      DECLARE @messageOwnerType INT;
                      SET @messageOwnerType = 3;
                      EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType

                      GO

                      DECLARE @messageOwnerType INT;
                      DECLARE @messageOwnerDB INT;
                      SET @messageOwnerType = 3;
                      SET @messageOwnerDB = DB_ID();

                      EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB


                      Maybe you missed something when writing the question.
                      I suppose that MessageOwnerID is the identity column of your table. To get this value, you first need to declare a table varible like @Temp with the structure of the column you want output from your insert:



                      DECLARE @Temp TABLE
                      (
                      MessageOwnerID INT
                      )


                      Second, you need to change your OUTPUT statement to insert this result into the variable:



                      OUTPUT Inserted.MessageOwnerID INTO @Temp


                      You now have this results in your table. You can write a select statement at the end of your procedure, or because you are sure you are inserting only one record, you can declare a variable @MessageOwnerID let's say. In order to return this value to the caller, you have to declare it as OUTPUT parameter. Set it's value to the value from the temp table and read it on execute. Your procedure is modifying like this:



                      ALTER PROCEDURE [dbo].[INSERT_MessageOwner]
                      @ownertype AS INT,
                      @ownertenant AS INT,
                      @MessageOwnerID INT = NULL OUTPUT
                      AS
                      BEGIN
                      SET NOCOUNT ON;

                      DECLARE @Temp TABLE
                      (
                      MessageOwnerID INT
                      )

                      INSERT INTO ADMINROTAS.dbo.MessageOwner
                      OUTPUT Inserted.MessageOwnerID INTO @Temp
                      VALUES (@ownertype, @ownertenant);

                      SELECT @MessageOwnerID = MessageOwnerID FROM @Temp
                      END


                      Remember the OUTPUT keyword on the parameter declaration!



                      The call to the procedure changes to this:



                      DECLARE @messageOwnerType INT;
                      DECLARE @messageOwnerDB INT;
                      DECLARE @MessageOwnerID INT;
                      SET @messageOwnerType = 3;
                      SET @messageOwnerDB = DB_ID();

                      EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB, @MessageOwnerID = @MessageOwnerID OUTPUT
                      SELECT @MessageOwnerID


                      Also, remember the OUTPUT keyword on all and the key-value pair of parameter name and variable (you should always use this way to call procedures).



                      Get a try and come back!






                      share|improve this answer



























                        0














                        I have no problem running this:



                        CREATE DATABASE ADMINROTAS

                        GO

                        CREATE TABLE ADMINROTAS.dbo.MessageOwner
                        (
                        MessageOwnerID INT IDENTITY PRIMARY KEY,
                        ownertype INT,
                        ownertenant INT
                        )

                        GO

                        SET ANSI_NULLS ON
                        GO
                        SET QUOTED_IDENTIFIER ON
                        GO

                        CREATE PROCEDURE [dbo].[INSERT_MessageOwner]
                        @ownertype AS INT,
                        @ownertenant AS INT
                        AS
                        BEGIN
                        SET NOCOUNT ON;

                        INSERT INTO ADMINROTAS.dbo.MessageOwner
                        OUTPUT Inserted.MessageOwnerID
                        VALUES (@ownertype, @ownertenant);
                        END

                        GO

                        DECLARE @messageOwnerType INT;
                        SET @messageOwnerType = 3;
                        EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType

                        GO

                        DECLARE @messageOwnerType INT;
                        DECLARE @messageOwnerDB INT;
                        SET @messageOwnerType = 3;
                        SET @messageOwnerDB = DB_ID();

                        EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB


                        Maybe you missed something when writing the question.
                        I suppose that MessageOwnerID is the identity column of your table. To get this value, you first need to declare a table varible like @Temp with the structure of the column you want output from your insert:



                        DECLARE @Temp TABLE
                        (
                        MessageOwnerID INT
                        )


                        Second, you need to change your OUTPUT statement to insert this result into the variable:



                        OUTPUT Inserted.MessageOwnerID INTO @Temp


                        You now have this results in your table. You can write a select statement at the end of your procedure, or because you are sure you are inserting only one record, you can declare a variable @MessageOwnerID let's say. In order to return this value to the caller, you have to declare it as OUTPUT parameter. Set it's value to the value from the temp table and read it on execute. Your procedure is modifying like this:



                        ALTER PROCEDURE [dbo].[INSERT_MessageOwner]
                        @ownertype AS INT,
                        @ownertenant AS INT,
                        @MessageOwnerID INT = NULL OUTPUT
                        AS
                        BEGIN
                        SET NOCOUNT ON;

                        DECLARE @Temp TABLE
                        (
                        MessageOwnerID INT
                        )

                        INSERT INTO ADMINROTAS.dbo.MessageOwner
                        OUTPUT Inserted.MessageOwnerID INTO @Temp
                        VALUES (@ownertype, @ownertenant);

                        SELECT @MessageOwnerID = MessageOwnerID FROM @Temp
                        END


                        Remember the OUTPUT keyword on the parameter declaration!



                        The call to the procedure changes to this:



                        DECLARE @messageOwnerType INT;
                        DECLARE @messageOwnerDB INT;
                        DECLARE @MessageOwnerID INT;
                        SET @messageOwnerType = 3;
                        SET @messageOwnerDB = DB_ID();

                        EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB, @MessageOwnerID = @MessageOwnerID OUTPUT
                        SELECT @MessageOwnerID


                        Also, remember the OUTPUT keyword on all and the key-value pair of parameter name and variable (you should always use this way to call procedures).



                        Get a try and come back!






                        share|improve this answer

























                          0












                          0








                          0







                          I have no problem running this:



                          CREATE DATABASE ADMINROTAS

                          GO

                          CREATE TABLE ADMINROTAS.dbo.MessageOwner
                          (
                          MessageOwnerID INT IDENTITY PRIMARY KEY,
                          ownertype INT,
                          ownertenant INT
                          )

                          GO

                          SET ANSI_NULLS ON
                          GO
                          SET QUOTED_IDENTIFIER ON
                          GO

                          CREATE PROCEDURE [dbo].[INSERT_MessageOwner]
                          @ownertype AS INT,
                          @ownertenant AS INT
                          AS
                          BEGIN
                          SET NOCOUNT ON;

                          INSERT INTO ADMINROTAS.dbo.MessageOwner
                          OUTPUT Inserted.MessageOwnerID
                          VALUES (@ownertype, @ownertenant);
                          END

                          GO

                          DECLARE @messageOwnerType INT;
                          SET @messageOwnerType = 3;
                          EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType

                          GO

                          DECLARE @messageOwnerType INT;
                          DECLARE @messageOwnerDB INT;
                          SET @messageOwnerType = 3;
                          SET @messageOwnerDB = DB_ID();

                          EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB


                          Maybe you missed something when writing the question.
                          I suppose that MessageOwnerID is the identity column of your table. To get this value, you first need to declare a table varible like @Temp with the structure of the column you want output from your insert:



                          DECLARE @Temp TABLE
                          (
                          MessageOwnerID INT
                          )


                          Second, you need to change your OUTPUT statement to insert this result into the variable:



                          OUTPUT Inserted.MessageOwnerID INTO @Temp


                          You now have this results in your table. You can write a select statement at the end of your procedure, or because you are sure you are inserting only one record, you can declare a variable @MessageOwnerID let's say. In order to return this value to the caller, you have to declare it as OUTPUT parameter. Set it's value to the value from the temp table and read it on execute. Your procedure is modifying like this:



                          ALTER PROCEDURE [dbo].[INSERT_MessageOwner]
                          @ownertype AS INT,
                          @ownertenant AS INT,
                          @MessageOwnerID INT = NULL OUTPUT
                          AS
                          BEGIN
                          SET NOCOUNT ON;

                          DECLARE @Temp TABLE
                          (
                          MessageOwnerID INT
                          )

                          INSERT INTO ADMINROTAS.dbo.MessageOwner
                          OUTPUT Inserted.MessageOwnerID INTO @Temp
                          VALUES (@ownertype, @ownertenant);

                          SELECT @MessageOwnerID = MessageOwnerID FROM @Temp
                          END


                          Remember the OUTPUT keyword on the parameter declaration!



                          The call to the procedure changes to this:



                          DECLARE @messageOwnerType INT;
                          DECLARE @messageOwnerDB INT;
                          DECLARE @MessageOwnerID INT;
                          SET @messageOwnerType = 3;
                          SET @messageOwnerDB = DB_ID();

                          EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB, @MessageOwnerID = @MessageOwnerID OUTPUT
                          SELECT @MessageOwnerID


                          Also, remember the OUTPUT keyword on all and the key-value pair of parameter name and variable (you should always use this way to call procedures).



                          Get a try and come back!






                          share|improve this answer













                          I have no problem running this:



                          CREATE DATABASE ADMINROTAS

                          GO

                          CREATE TABLE ADMINROTAS.dbo.MessageOwner
                          (
                          MessageOwnerID INT IDENTITY PRIMARY KEY,
                          ownertype INT,
                          ownertenant INT
                          )

                          GO

                          SET ANSI_NULLS ON
                          GO
                          SET QUOTED_IDENTIFIER ON
                          GO

                          CREATE PROCEDURE [dbo].[INSERT_MessageOwner]
                          @ownertype AS INT,
                          @ownertenant AS INT
                          AS
                          BEGIN
                          SET NOCOUNT ON;

                          INSERT INTO ADMINROTAS.dbo.MessageOwner
                          OUTPUT Inserted.MessageOwnerID
                          VALUES (@ownertype, @ownertenant);
                          END

                          GO

                          DECLARE @messageOwnerType INT;
                          SET @messageOwnerType = 3;
                          EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType

                          GO

                          DECLARE @messageOwnerType INT;
                          DECLARE @messageOwnerDB INT;
                          SET @messageOwnerType = 3;
                          SET @messageOwnerDB = DB_ID();

                          EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB


                          Maybe you missed something when writing the question.
                          I suppose that MessageOwnerID is the identity column of your table. To get this value, you first need to declare a table varible like @Temp with the structure of the column you want output from your insert:



                          DECLARE @Temp TABLE
                          (
                          MessageOwnerID INT
                          )


                          Second, you need to change your OUTPUT statement to insert this result into the variable:



                          OUTPUT Inserted.MessageOwnerID INTO @Temp


                          You now have this results in your table. You can write a select statement at the end of your procedure, or because you are sure you are inserting only one record, you can declare a variable @MessageOwnerID let's say. In order to return this value to the caller, you have to declare it as OUTPUT parameter. Set it's value to the value from the temp table and read it on execute. Your procedure is modifying like this:



                          ALTER PROCEDURE [dbo].[INSERT_MessageOwner]
                          @ownertype AS INT,
                          @ownertenant AS INT,
                          @MessageOwnerID INT = NULL OUTPUT
                          AS
                          BEGIN
                          SET NOCOUNT ON;

                          DECLARE @Temp TABLE
                          (
                          MessageOwnerID INT
                          )

                          INSERT INTO ADMINROTAS.dbo.MessageOwner
                          OUTPUT Inserted.MessageOwnerID INTO @Temp
                          VALUES (@ownertype, @ownertenant);

                          SELECT @MessageOwnerID = MessageOwnerID FROM @Temp
                          END


                          Remember the OUTPUT keyword on the parameter declaration!



                          The call to the procedure changes to this:



                          DECLARE @messageOwnerType INT;
                          DECLARE @messageOwnerDB INT;
                          DECLARE @MessageOwnerID INT;
                          SET @messageOwnerType = 3;
                          SET @messageOwnerDB = DB_ID();

                          EXECUTE [ADMINROTAS].[dbo].INSERT_MessageOwner @messageOwnerType, @messageOwnerDB, @MessageOwnerID = @MessageOwnerID OUTPUT
                          SELECT @MessageOwnerID


                          Also, remember the OUTPUT keyword on all and the key-value pair of parameter name and variable (you should always use this way to call procedures).



                          Get a try and come back!







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered yesterday









                          Nițu AlexandruNițu Alexandru

                          529526




                          529526



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044112%2fexecuting-stored-procedure-one-argument-is-too-few-two-is-too-many%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                              2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                              Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme