I am new to SQL and trying to write a stored procedure. I am having some difficulties to get default values as an output result.
I have 2 table:
Student_Input:
InputID SectionID ParameterName Sequence
------------------------------------------------
1 100 FirstName 1
2 100 MiddleName 2
3 100 LastName 3
Student_Input_details:
ParameterName ParameterValue DefaultValue
-----------------------------------------------------
FirstName John 1
FirstName Troy 0
FirstName Mark 0
I am trying to call ParameterName from Student_Input and Its default value from Student_Input_Details as an output in one table. I am trying with following query but I am getting following error:
Msg 201, Level 16, State 4, Procedure Getparameterdefaultvalues, Line 0
Procedure or function 'Getparameterdefaultvalues' expects parameter '@ParameterValue', which was not supplied.
I am sure I am missing something important here.
My query is below. I am learning , it may be an easy question. Thx........
CREATE PROCEDURE Getparameterdefaultvalues
(
@ParameterName varchar(50) ,
@ParameterValue varchar(50) OUT
)
AS
BEGIN
SELECT @ParameterValue = DefaultValue FROM ParameterInput_Values
WHERE ParameterName=@ParameterName
END
DECLARE @ParameterValue varchar(50)
EXEC Getparameterdefaultvalues @ParameterName = 1, @ParameterValue OUTPUT
PRINT 'Result is: ' + @ParameterValue
I need result like (i.e. ParameterName should only display its default value at runtime):
ParameterName ParameterValue
----------------------------------
FirstName John
I have tried on other blogs but couldn't resolve this. Apologies If my question is not so cleared. Any help would be great!! Thx
Pretty simple and easy: your stored procedure expects two parameters - @ParameterName and @ParameterValue - but your call only supplies one...
You should call your stored procedure like this:
DECLARE @ParameterValue varchar(50)
EXEC Getparameterdefaultvalues @ParameterName = 1, @ParameterValue = @ParameterValue OUTPUT
PRINT 'Result is: ' + @ParameterValue
Also: you're returning the retrieved value as an output parameter - so you're getting back a single value into a variable - you're not getting back a result set (rows/columns).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With