ComeçarComece de graça

One in one out

Create a function named SumRideHrsSingleDay() which returns the total ride time in hours for the @DateParm parameter passed.

Este exercício faz parte do curso

Writing Functions and Stored Procedures in SQL Server

Ver curso

Instruções do exercício

  • Define input parameter of type date - @DateParm and a return data type of numeric.
  • Use BEGIN/END keywords.
  • In your SELECT statement, SUM the difference between the StartDate and EndDate of the transactions that have the same StartDate value as the parameter passed.
  • Use CAST to compare the date portion of StartDate to the @DateParm.

Exercício interativo prático

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

-- Create SumRideHrsSingleDay
___ ___ SumRideHrsSingleDay (___ date)
-- Specify return data type
___ ___
AS
-- Begin
___
RETURN
-- Add the difference between StartDate and EndDate
(SELECT SUM(DATEDIFF(second, StartDate, EndDate))/3600
FROM CapitalBikeShare
 -- Only include transactions where StartDate = @DateParm
WHERE ___(StartDate AS ___) = ___)
-- End
___
Editar e executar o código