Multiple inputs one output
Often times you will need to pass more than one parameter to a function. Create a function that accepts @StartDateParm and @EndDateParm and returns the total ride hours for all transactions that have a StartDate within the parameter values.
Este ejercicio forma parte del curso
Writing Functions and Stored Procedures in SQL Server
Instrucciones del ejercicio
- Create a function named
SumRideHrsDateRangewith@StartDateParmand@EndDateParmas the input parameters ofdatetimedata type. - Specify the return data type to be
numeric. - Use a select statement to sum the difference between the
StartDateandEndDateof the transactions. - Only include transactions that have a
StartDategreater than@StartDateParmand less than@EndDateParm.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
-- Create the function
___ ___ SumRideHrsDateRange (___ ___, ___ ___)
-- Specify return data type
RETURNS ___
AS
BEGIN
RETURN
-- Sum the difference between StartDate and EndDate
(___ ___(___(second, StartDate, EndDate))/3600
FROM CapitalBikeShare
-- Include only the relevant transactions
WHERE StartDate > ___ and StartDate < ___)
END