Execute stored procedure with an Output parameter?

2020-01-24 10:49发布

I have a stored procedure that I am trying to test. I am trying to test it through SQL Management Studio. In order to run this test I enter ...

exec my_stored_procedure 'param1Value', 'param2Value'

The final parameter is an output parameter. However, I do not know how to test a stored procedure with output parameters.

How do I run a stored procedure with an output parameter?

14条回答
Deceive 欺骗
2楼-- · 2020-01-24 11:37

>Try this its working fine for the multiple output parameter:

CREATE PROCEDURE [endicia].[credentialLookup]
@accountNumber varchar(20),
@login varchar(20) output,
@password varchar(50) output
AS
BEGIN
SET NOCOUNT ON;
SELECT top 1 @login = [carrierLogin],@password = [carrierPassword]
  FROM [carrier_account] where carrierLogin = @accountNumber
  order by clientId, id
END

Try for the result: 
SELECT *FROM [carrier_account] 
DECLARE @login varchar(20),@password varchar(50)
exec [endicia].[credentialLookup] '588251',@login OUTPUT,@password OUTPUT
SELECT 'login'=@login,'password'=@password
查看更多
Summer. ? 凉城
3楼-- · 2020-01-24 11:41

With this query you can execute any stored procedure(With or Without output parameter):

DECLARE @temp varchar(100)  
EXEC my_sp
    @parameter1 = 1, 
    @parameter2 = 2, 
    @parameter3 = @temp output, 
    @parameter4 = 3, 
    @parameter5 = 4
PRINT @temp

Here datatype of @temp should be same as @parameter3 within SP.

Hope this helps..

查看更多
登录 后发表回答