Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
this is my store procedure named adminDegree
SQL
USE [szicExam]
GO
/****** Object:  StoredProcedure [dbo].[AdminDegree]    Script Date: 09/12/2013 05:14:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[AdminDegree]
	-- Add the parameters for the stored procedure here
		 @Mode varchar(50)
		,@DegreeID int
        ,@DegreeName varchar(50)
AS
	IF @Mode='Select'
	BEGIN
	SELECT [ID]
      ,[DegreeID]
      ,[DegreeName]
	FROM [szicExam].[dbo].[Degree]
	END
	
	IF @Mode='Insert'
	BEGIN
	INSERT INTO [szicExam].[dbo].[Degree]
           ([DegreeID] ,[DegreeName])
    VALUES (@DegreeID ,@DegreeName)
	END

	IF @Mode='Update'
	BEGIN
	UPDATE [szicExam].[dbo].[Degree]
	SET [DegreeID] = @DegreeID ,[DegreeName] = @DegreeName
	WHERE DegreeID=@DegreeId
	END

	IF @Mode='Delete'
	BEGIN
	DELETE FROM [szicExam].[dbo].[Degree]
    WHERE DegreeID=@DegreeId
	END


but when i try to execute using this code
SQL
exec dbo.AdminDegree @Mode = 'Select'


and error comes in

ASM
sg 201, Level 16, State 4, Procedure AdminDegree, Line 0
Procedure or function 'AdminDegree' expects parameter '@DegreeID', which was not supplied.


i dont know why it is showing becuase i didnot provid any where clause for DegreeID
Posted
Updated 11-Sep-13 2:27am
v2
Comments
[no name] 11-Sep-13 8:27am    
Well the obvious thing to do would be to supply the parameter that the SP expects to get.
ArunRajendra 11-Sep-13 8:30am    
Try this exec dbo.AdminDegree @Mode = 'Select', null, null
Muhamad Faizan Khan 11-Sep-13 10:33am    
exec dbo.AdminDegree @Mode= 'select',@DegreeID=null, @DegreeName=null
i did by it, its working but i don't want to do this
[no name] 11-Sep-13 8:47am    
"i didnot provid any where clause for DegreeID" sure you did. It's used all thoughout your SP!
Muhamad Faizan Khan 11-Sep-13 10:36am    
it means the variable i declare every time i call store procedures i need to provide all parameters

Your SP expects 3 parameters, which are obligatory:
  • @Mode varchar(50)
  • @DegreeID int
  • @DegreeName varchar(50)



Please, see:
Execute a Stored Procedure[^]
Specify Parameters[^]
How can I use optional parameters in a T-SQL stored procedure?[^]

[EDIT #1]
Please, read my question to the comment.

SQL
CREATE PROCEDURE Sales.uspGetSalesYTD
@SalesPerson nvarchar(50) = NULL  -- NULL default value
AS 
    SET NOCOUNT ON; 

-- Validate the @SalesPerson parameter.
IF @SalesPerson IS NULL
BEGIN
   PRINT 'ERROR: You must specify the last name of the sales person.'
   RETURN
END


SQL
-- Run the procedure without specifying an input value.
EXEC Sales.usp_GetSalesYTD;
GO
-- Run the procedure with an input value.
EXEC Sales.usp_GetSalesYTD N'Blythe';
GO

[/EDIT]
 
Share this answer
 
v2
Comments
Muhamad Faizan Khan 11-Sep-13 10:30am    
i declare 3 variables it means i every time need to pass value for it, but for 'select' query i don't require remaining two. how i overcome this problem?? i don't want to make a separate procedure for that.
Maciej Los 11-Sep-13 10:40am    
Have you read related articles? I doubt ;(
Please, see my answer now.
Muhamad Faizan Khan 11-Sep-13 11:08am    
Yes you right because reading of all thing is really hard for me. but i saw a glance.
And thanks for solution it is working. You know this is the summery of all links.
thanks rate5
Maciej Los 11-Sep-13 13:44pm    
Thanks and you're welcome ;)
You Declared three input parameters those are
SQL
@Mode varchar(50)
        ,@DegreeID int
        ,@DegreeName varchar(50)
but you are passing single parameter that is Mode so it's gives error message is what you got
 
Share this answer
 
Comments
Muhamad Faizan Khan 11-Sep-13 10:31am    
i declare 3 variables it means i every time need to pass value for it, but for 'select' query i don't require remaining two. how i overcome this problem?? i don't want to make a separate procedure for that.
pass @DegreeID too

exec dbo.AdminDegree @Mode = 'Select' ,@DegreeID=2 like
 
Share this answer
 
Comments
Muhamad Faizan Khan 11-Sep-13 8:45am    
why i provide degree id?? no where clause for that
satyamkotakonda 11-Sep-13 9:15am    
Your question is correct but one thing you have to remember that is procedure accepts parameters and those parameters are use full or not to proceed further
pass @DegreeID too

exec dbo.AdminDegree @Mode = 'Select' ,@DegreeID=2
 
Share this answer
 
Comments
Thanks7872 11-Sep-13 8:35am    
Remove the duplicate answer.
Muhamad Faizan Khan 11-Sep-13 8:45am    
why i provide degree id?? no where clause for that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900