ref: https://support.microsoft.com/en-us/kb/262499
DECLARE @SQLString NVARCHAR(500) DECLARE @ParmDefinition NVARCHAR(500) DECLARE @IntVariable INT DECLARE @Lastlname varchar(30) SET @SQLString = N'SELECT @LastlnameOUT = max(lname) FROM pubs.dbo.employee WHERE job_lvl = @level' SET @ParmDefinition = N'@level tinyint, @LastlnameOUT varchar(30) OUTPUT' SET @IntVariable = 35 EXECUTE sp_executesql @SQLString, @ParmDefinition, @level = @IntVariable, @LastlnameOUT=@Lastlname OUTPUT SELECT @Lastlname ------------------------------------------------------------- CREATE PROCEDURE Myproc @parm nvarchar(10), @parm1OUT nvarchar(30) OUTPUT, @parm2OUT nvarchar(30) OUTPUT AS SELECT @parm1OUT=N'参数1parm 1' + @parm SELECT @parm2OUT=N'参数2parm 2' + @parm GO DECLARE @SQLString NVARCHAR(500) DECLARE @ParmDefinition NVARCHAR(500) DECLARE @parmIN nvarchar(10) DECLARE @parmRET1 nvarchar(30) DECLARE @parmRET2 nvarchar(30) SET @parmIN=' returned' SET @SQLString=N'EXEC Myproc @parm, @parm1OUT OUTPUT, @parm2OUT OUTPUT' SET @ParmDefinition=N'@parm nvarchar(10), @parm1OUT nvarchar(30) OUTPUT, @parm2OUT nvarchar(30) OUTPUT' /* EXECUTE sp_executesql @SQLString, @ParmDefinition, @parm1OUT=@parmRET1 OUTPUT,@parm2OUT=@parmRET2 OUTPUT, @parm=@parmIN */ --可以不指定参数名,但位置要正确 EXECUTE sp_executesql @SQLString, @ParmDefinition, @parmIN, @parmRET1 OUTPUT, @parmRET2 OUTPUT SELECT @parmRET1 AS "parameter 1", @parmRET2 AS "parameter 2" GO drop procedure Myproc