Answers:
最简单的方法是right-click
在procedure
在SQL Server管理Studio(SSMS)
选择 execute stored procedure...
并根据提示为输入参数添加值。
SSMS
然后将生成代码以在新的查询窗口中运行proc,并为您执行该代码。您可以研究生成的代码以了解其完成方式。
execute
命令,上下文菜单只有一个modify
。
你可以这样做 :
declare @rowCount int
exec yourStoredProcedureName @outputparameterspOf = @rowCount output
进行检查,在过程定义中,前两个参数是输入参数,第三个参数是输出参数。
DECLARE @PK_Code INT;
EXEC USP_Validate_Login 'ID', 'PWD', @PK_Code OUTPUT
SELECT @PK_Code
从http://support.microsoft.com/kb/262499
例:
CREATE PROCEDURE Myproc
@parm varchar(10),
**@parm1OUT varchar(30) OUTPUT**,
**@parm2OUT varchar(30) OUTPUT**
AS
SELECT @parm1OUT='parm 1' + @parm
SELECT @parm2OUT='parm 2' + @parm
GO
DECLARE @SQLString NVARCHAR(500)
DECLARE @ParmDefinition NVARCHAR(500)
DECLARE @parmIN VARCHAR(10)
DECLARE @parmRET1 VARCHAR(30)
DECLARE @parmRET2 VARCHAR(30)
SET @parmIN=' returned'
SET @SQLString=N'EXEC Myproc @parm,
@parm1OUT OUTPUT, @parm2OUT OUTPUT'
SET @ParmDefinition=N'@parm varchar(10),
@parm1OUT varchar(30) OUTPUT,
@parm2OUT varchar(30) OUTPUT'
EXECUTE sp_executesql
@SQLString,
@ParmDefinition,
@parm=@parmIN,
@parm1OUT=@parmRET1 OUTPUT,@parm2OUT=@parmRET2 OUTPUT
SELECT @parmRET1 AS "parameter 1", @parmRET2 AS "parameter 2"
GO
DROP PROCEDURE Myproc
希望这可以帮助!
Create Procedure [dbo].[test]
@Name varchar(100),
@ID int Output
As
Begin
SELECT @ID = UserID from tbl_UserMaster where Name = @Name
Return;
END
Declare @ID int
EXECUTE [dbo].[test] 'Abhishek',@ID OUTPUT
PRINT @ID
首先,声明输出变量:
DECLARE @MyOutputParameter INT;
然后,执行存储过程,您可以在没有参数名称的情况下执行存储过程,如下所示:
EXEC my_stored_procedure 'param1Value', @MyOutputParameter OUTPUT
或带有参数名称:
EXEC my_stored_procedure @param1 = 'param1Value', @myoutput = @MyOutputParameter OUTPUT
最后,您可以通过执行以下命令查看输出结果SELECT
:
SELECT @MyOutputParameter
>尝试此方法对于多个输出参数可以正常工作:
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
CREATE PROCEDURE DBO.MY_STORED_PROCEDURE
(@PARAM1VALUE INT,
@PARAM2VALUE INT,
@OUTPARAM VARCHAR(20) OUT)
AS
BEGIN
SELECT * FROM DBO.PARAMTABLENAME WHERE PARAM1VALUE=@PARAM1VALUE
END
DECLARE @OUTPARAM2 VARCHAR(20)
EXEC DBO.MY_STORED_PROCEDURE 1,@OUTPARAM2 OUT
PRINT @OUTPARAM2
这是存储过程
create procedure sp1
(
@id as int,
@name as nvarchar(20) out
)
as
begin
select @name=name from employee where id=@id
end
这是执行程序的方式
declare @name1 nvarchar(10)
exec sp1 1,@name1 out
print @name1
请检查以下示例以通过执行存储过程获取输出变量值。
DECLARE @return_value int,
@Ouput1 int,
@Ouput2 int,
@Ouput3 int
EXEC @return_value = 'Your Sp Name'
@Param1 = value1,
@Ouput1 = @Ouput1 OUTPUT,
@Ouput2 = @Ouput2 OUTPUT,
@Ouput3 = @Ouput3 OUTPUT
SELECT @Ouput1 as N'@Ouput1',
@Ouput2 as N'@Ouput2',
@Ouput3 as N'@Ouput3'