One in one out
Create a function named SumRideHrsSingleDay() which returns the total ride time in hours for the @DateParm parameter passed.
Questo esercizio fa parte del corso
Writing Functions and Stored Procedures in SQL Server
Istruzioni dell'esercizio
- Define input parameter of type
date-@DateParmand a return data type ofnumeric. - Use
BEGIN/ENDkeywords. - In your
SELECTstatement,SUMthe difference between theStartDateandEndDateof the transactions that have the sameStartDatevalue as the parameter passed. - Use
CASTto compare thedateportion ofStartDateto the@DateParm.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
-- 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
___