Execute Stored Procedures

 

EXECUTE with OUTPUT parameter

Execute the dbo.cuspSumRideHrsSingleDay stored procedure and capture the output parameter.


DECLARE @RideHrs AS numeric(18,0)

-- Execute the stored procedure

EXEC dbo.cuspSumRideHrsSingleDay

    -- Pass the input parameter

@DateParm = '3/1/2018',

    -- Store the output in @RideHrs

@RideHrsOut =  @RideHrs OUTPUT

-- Select @RideHrs

SELECT @RideHrs AS RideHours



EXECUTE with the return value

Execute dbo.cuspRideSummaryUpdate to change the RideHours to 300 for '3/1/2018'. Store the return code from the stored procedure.

DECLARE @ReturnStatus AS int

-- Execute the SP, storing the result in @ReturnStatus

EXEC @ReturnStatus = dbo.cuspRideSummaryUpdate

    -- Specify @DateParm

@DateParm= '3/1/2018',

    -- Specify @RideHrs

@RideHrs = 300


-- Select the columns of interest

SELECT

@ReturnStatus AS ReturnStatus,

    Date,

    RideHours

FROM RideSummary

WHERE Date = '3/1/2018';


Exercise

EXECUTE with OUTPUT & return value

Store and display both the output parameter and return code when executing dbo.cuspRideSummaryDelete SP.


-- Create @ReturnStatus

DECLARE @ReturnStatus AS INT

-- Create @RowCount

DECLARE @RowCount AS INT


-- Execute the SP, storing the result in @ReturnStatus

EXEC @ReturnStatus = dbo.cuspRideSummaryDelete

    -- Specify @DateParm

@DateParm = '3/1/2018',

    -- Specify RowCountOut

@RowCountOut = @RowCount OUTPUT


-- Select the columns of interest

SELECT

@ReturnStatus AS ReturnStatus,

    @RowCount AS 'RowCount';


Comments

Popular posts from this blog

Binomial Test in Python

Slicing and Indexing in Python Pandas

Python Syntax and Functions Part2 (Summary Statistics)