IniziaInizia gratis

CREATE PROCEDURE with OUTPUT

Create a Stored Procedure named cuspSumRideHrsSingleDay in the dbo schema that accepts a date and returns the total ride hours for the date passed.

Questo esercizio fa parte del corso

Writing Functions and Stored Procedures in SQL Server

Visualizza il corso

Istruzioni dell'esercizio

  • Create a stored procedure called cuspSumRideHrsSingleDay in the dbo schema.
  • Declare @DateParm as the input parameter and @RideHrsOut as the output parameter.
  • Don't send the row count to the caller.
  • Assign the query result to @RideHrsOut and include the RETURN keyword.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

-- Create the stored procedure
___ ___ dbo.___
    -- Declare the input parameter
	___ date,
    -- Declare the output parameter
	___ numeric ___
AS
-- Don't send the row count 
___ ___ ___
BEGIN
-- Assign the query result to @RideHrsOut
___
	___ = SUM(DATEDIFF(second, StartDate, EndDate))/3600
FROM CapitalBikeShare
-- Cast StartDate as date and compare with @DateParm
WHERE CAST(StartDate AS date) = @DateParm
RETURN
END
Modifica ed esegui il codice