Mega Code Archive

 
Categories / MSSQL Tutorial / Procedure Function
 

Stored procedure returning value using an Output parameter

7> 8> CREATE PROCEDURE spCalculateOutput 9>   @Value1      Float 10>  , @Value2      Float 11>  , @Operator    Char(10) 12>  , @Result      Float     Output 13> As 14>  IF @Operator = '+' 15>     SET @Result = @Value1 + @Value2 16>  ELSE IF @Operator = '-' 17>     SET @Result = @Value1 - @Value2 18>  ELSE IF @Operator = '*' 19>     SET @Result = @Value1 * @Value2 20>  ELSE IF @Operator = '/' 21>     SET @Result = @Value1 / @Value2 22> 23> -- Declare a variable for the result value 24> Declare @Out Float 25> -- Execute the procedure & assign the result 26> Execute spCalculate_Output 123, 456, '+' 27> -- Print the result value 28> Print @Out 29> 30> 31> drop procedure spCalculateOutput; 32> GO Cannot add rows to sysdepends for the current object because it depends on the missing object 'spCalculate_Output'. The object will still be created.