0

I am trying to add data in single table using a SQL Server stored procedure and I am getting an error

procedure or function x has too many argument specified

Also how can I get newly created ID of record as I need to update multiple tables using these IDs

I am using SQL Server 2012

Many thanks

ALTER PROCEDURE [dbo].[CreateNewFunctionsNavigation]
   @FunctionName nvarchar(250),
   @Hierarchy_Level int
AS
BEGIN
   SET NOCOUNT ON;

   INSERT [dbo].[Navigation_Functions] ([FunctionName], [Hierarchy_Level])
   VALUES(@FunctionName, @Hierarchy_Level)
END

Execution of stored procedure:

DECLARE @return_value int

EXEC    @return_value = [dbo].[CreateNewFunctionsNavigation]
        @FunctionName = N'DSD',
        @Hierarchy_Level = 3

SELECT  'Return Value' = @return_value
GO

My SQL for Function table

USE [MySolution01_DB]
GO

/****** Object:  Table [dbo].[Navigation_Functions]    Script Date: 06/01/2015 15:58:57 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Navigation_Functions](
 [Function_ID] [int] IDENTITY(1,1) NOT NULL,
 [FunctionName] [nvarchar](250) NOT NULL,
 [Hierarchy_Level] [int] NOT NULL,
CONSTRAINT [PK_Functions] PRIMARY KEY CLUSTERED 
(
  [Function_ID] ASC
 )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,   ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

  GO

3 Answers 3

1

It should be

INSERT INTO [dbo].[Navigation_Functions] ([FunctionName], [Hierarchy_Level])

I created a sample table

CREATE TABLE [dbo].[Navigation_Functions](
    [NavigationFunctionId] [int] IDENTITY(1,1) NOT NULL,
    [FunctionName] [nvarchar](250) NULL,
    [Hierarchy_Level] [int] NULL,
 CONSTRAINT [PK_Navigation_Functions] PRIMARY KEY CLUSTERED 
(
    [NavigationFunctionId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Sign up to request clarification or add additional context in comments.

6 Comments

What's your table structure look like? Is your primary key column set to be the primary key? Is it an int type? If so, do you have Is Identity set to Yes under Identity Specification?
I added a sample script of the table creation.
yes I have primary key FunctionID whose Identity set to yes
i have updated my question with SQL Script for my table
Everything you posted worked for me in SQL Management Studio. I used it verbatim. Are you calling this from some other place like a web application?
|
1

You can get the last ID by: SELECT SCOPE_IDENTITY();

Comments

0
USE [MySolution01_DB]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[CreateNewFunctionsNavigation]
  @FunctionName nvarchar(250),
  @Hierarchy_Level INT,
  @Function_identity INT OUTPUT
AS
BEGIN
SET NOCOUNT ON;

INSERT INTO [dbo].[Navigation_Functions] ([FunctionName],[Hierarchy_Level] ) 
VALUES(@FunctionName, @Hierarchy_Level);

   SET @Function_identity=SCOPE_IDENTITY()
   RETURN @Function_identity

RETURN
END

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.