Execute TVF into variable
Remember the table value function you created earlier in this chapter named SumStationStats?. It accepts a datetime parameter and returns the ride count and total ride duration for each starting station where the start date matches the input parameter. Execute SumStationStats now and store the results in a table variable.
Diese Übung ist Teil des Kurses
Writing Functions and Stored Procedures in SQL Server
Anleitung zur Übung
- Create a table variable named
@StationStatswith columnsStartStation,RideCount, andTotalDuration. - Execute the
SumStationStatsfunction and pass'3/15/2018'as the input parameter. - Use
INSERT INTOto populate the@StationStatstable variable with the results of the function. - Select all the records from the table variable.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
-- Create @StationStats
___ ___ ___(
StartStation nvarchar(100),
RideCount int,
TotalDuration numeric)
-- Populate @StationStats with the results of the function
___ ___ ___
SELECT TOP 10 *
-- Execute SumStationStats with 3/15/2018
FROM dbo.___('3/15/2018')
ORDER BY RideCount DESC
-- Select all the records from @StationStats
___ *
___ ___