Executing a simple stored procedure in SQL Server Management Studio

This is a simple stored procedure written in SQL Server Management Studio.

It compiles great but I have problems invoking it :(

CREATE PROCEDURE [dbo].[DetermineVoltage]
   @itemDescription varchar(225) ,
   @voltageRating varchar(225) OUTPUT
AS
BEGIN
   SELECT 
       @voltageRating = REVERSE(SUBSTRING(REVERSE(@itemDescription),
       charindex(' V', REVERSE(@itemDescription)) + 2,
    CHARINDEX(' ', REVERSE(@itemDescription), charindex(' V', REVERSE(@itemDescription)) + 1) - charindex(' V', REVERSE(@itemDescription)) - 2))
   RETURN
END

In SQL Server Management Studio, when I execute this stored procedure like this:

DECLARE  @voltageRating VARCHAR(225) 
exec dbo.DetermineVoltage['test 20V', @voltageRating]

I get an error

Procedure or function 'DetermineVoltage' expects parameter '@voltageRating', which was not supplied.

There are many SO answers which discusses the same error message but when executed from a C# program.

But, in my case, how to execute a stored procedure within SQL Server Management Studio ?

Upvotes: 2

Views: 13394

Answers (1)

GSerg
GSerg

Reputation: 78185

declare @voltageRating varchar(225);
exec dbo.DetermineVoltage 'test 20V', @voltageRating output;

As a side note, you might want to convert this procedure to a function.

Upvotes: 9

Related Questions