I try to make a query and it works well, but when i put it in a stored procedure.I can't figure out whats wrong with my code. It says
Procedure or function has too many arguments specified

Stored procedure code

******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[uspEnrolledStudents]
    -- Add the parameters for the stored procedure here
@SchoolYear Nvarchar(20),
@levels Nvarchar(20),
@Section Nvarchar(20),
@DateEnrolled Date

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;     
            DECLARE @studID INT


    INSERT INTO StudentHistory(SchoolYear,Levels,Section,DateEnrolled,StudentID) 
        VALUES(@SchoolYear,@levels,@Section,@DateEnrolled,@studID)

END

I Execute it with this code:

EXEC dbo.uspEnrolledStudents '2016-2017','GRADE 11','SAINT RAMON','2015-1-2','380'

You are passing 5 arguments instead of the 4 that the procedure is defined to use. It looks like the 5th argument is the @studID you are declaring later in the procedure. Why not place that in the argument list?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.