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#
Does .bashrc contain syntax errors?
What does "Four-F." mean?
Can you move over difficult terrain with only 5 feet of movement?
In Aliens, how many people were on LV-426 before the Marines arrived?
How to terminate ping <dest> &
Is there a hypothetical scenario that would make Earth uninhabitable for humans, but not for (the majority of) other animals?
gerund and noun applications
Could Sinn Fein swing any Brexit vote in Parliament?
What does Deadpool mean by "left the house in that shirt"?
Hausdorff dimension of the boundary of fibres of Lipschitz maps
How can an organ that provides biological immortality be unable to regenerate?
Practical application of matrices and determinants
How are passwords stolen from companies if they only store hashes?
Brake pads destroying wheels
Generic TVP tradeoffs?
Describing a chess game in a novel
What is the English word for a graduation award?
Do native speakers use "ultima" and "proxima" frequently in spoken English?
Comment Box for Substitution Method of Integrals
Should I be concerned about student access to a test bank?
What favor did Moody owe Dumbledore?
Geography in 3D perspective
In what cases must I use 了 and in what cases not?
Do I need to consider instance restrictions when showing a language is in P?
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
581k13011221268
581k13011221268
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
16616
16616
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 Mar 13 at 15:22
Nițu AlexandruNițu Alexandru
543627
543627
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