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#
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
add a comment |
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
add a comment |
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
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
tsql stored-procedures sql-server-2014
edited Mar 7 at 13:03
marc_s
581k13011211268
581k13011211268
asked Mar 7 at 12:44
hardyahardya
165
165
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
add a comment |
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!
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
edited Mar 7 at 17:18
answered Mar 7 at 17:07
JBJJBJ
1665
1665
add a comment |
add a comment |
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!
add a comment |
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!
add a comment |
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!
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!
answered yesterday
Nițu AlexandruNițu Alexandru
529526
529526
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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