Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute stored procedure with an Output parameter?

The easy way is to right-click on the procedure in Sql Server Management Studio(SSMS),

select execute stored procedure...

and add values for the input parameters as prompted.

SSMS will then generate the code to run the proc in a new query window, and execute it for you. You can study the generated code to see how it is done.


you can do this :

declare @rowCount int
exec yourStoredProcedureName @outputparameterspOf = @rowCount output

Return val from procedure

ALTER PROCEDURE testme @input  VARCHAR(10),
                       @output VARCHAR(20) output
AS
  BEGIN
      IF @input >= '1'
        BEGIN
            SET @output = 'i am back';

            RETURN;
        END
  END

DECLARE @get VARCHAR(20);

EXEC testme
  '1',
  @get output

SELECT @get 

Check this, Where first two parameters are input parameters and 3rd one is Output parameter in Procedure definition.

DECLARE @PK_Code INT;
EXEC USP_Validate_Login  'ID', 'PWD', @PK_Code OUTPUT
SELECT @PK_Code

Procedure Example :

Create Procedure [dbo].[test]
@Name varchar(100),
@ID int Output   
As  
Begin   
SELECT @ID = UserID from tbl_UserMaster where  Name = @Name   
Return;
END     

How to call this procedure

Declare @ID int    
EXECUTE [dbo].[test] 'Abhishek',@ID OUTPUT   
PRINT @ID