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.
Cet exercice fait partie du cours
Writing Functions and Stored Procedures in SQL Server
Instructions
- 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.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
-- 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