Executing a simple stored procedure in SQL Server Management Studio

11,141
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.

Share:
11,141
now he who must not be named.
Author by

now he who must not be named.

#SOreadytohelp There is this joy in helping others. Thanks SO

Updated on June 13, 2022

Comments

  • now he who must not be named.
    now he who must not be named. almost 2 years

    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 ?

  • now he who must not be named.
    now he who must not be named. over 10 years
    Cool. Works great. Thanks. Can you kindly tell me from where do you refer? I googled a lot but could not find.
  • aelveborn
    aelveborn over 10 years
    @nowhewhomustnotbenamed where do you refer -- EXECUTE (Transact-SQL)
  • now he who must not be named.
    now he who must not be named. over 10 years
    Thanks again. Time to sharpen my googling skills ;)