Maintaining UDF

 Change the SumStationStats function to enable SCHEMABINDING. Also change the parameter name to @EndDate and compare to EndDate of CapitalBikeShare table.


-- Update SumStationStats

CREATE OR ALTER FUNCTION dbo.SumStationStats(@EndDate AS date)

-- Enable SCHEMABINDING

RETURNS TABLE WITH SCHEMABINDING

AS

RETURN

SELECT

StartStation,

    COUNT(ID) AS RideCount,

    SUM(DURATION) AS TotalDuration

FROM dbo.CapitalBikeShare

-- Cast EndDate as date and compare to @EndDate

WHERE CAST(EndDate AS Date) = @EndDate

GROUP BY StartStation;

Comments

Popular posts from this blog

Binomial Test in Python

Slicing and Indexing in Python Pandas

Python Syntax and Functions Part2 (Summary Statistics)