ComeçarComece de graça

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 exercício faz parte do curso

Writing Functions and Stored Procedures in SQL Server

Ver curso

Instruções do exercício

  • Create a function named SumRideHrsDateRange with @StartDateParm and @EndDateParm as the input parameters of datetime data type.
  • Specify the return data type to be numeric.
  • Use a select statement to sum the difference between the StartDate and EndDate of the transactions.
  • Only include transactions that have a StartDate greater than @StartDateParm and less than @EndDateParm.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

-- 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
Editar e executar o código