Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 714
now he who must not be named. Avatar asked Apr 30 '26 11:04

now he who must not be named.


1 Answers

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.

like image 89
GSerg Avatar answered May 03 '26 00:05

GSerg