Executing UDF
-- Create @RideHrs
DECLARE @RideHrs AS numeric
-- Execute SumRideHrsSingleDay function and store the result in @RideHrs
EXEC @RideHrs = dbo.SumRideHrsSingleDay @DateParm = '3/5/2018'
SELECT
'Total Ride Hours for 3/5/2018:',
@RideHrs
Executing a Table Function
-- Create @StationStats
DECLARE @StationStats TABLE(
StartStation nvarchar(100),
RideCount int,
TotalDuration numeric)
-- Populate @StationStats with the results of the function
INSERT INTO @StationStats
SELECT TOP 10 *
-- Execute SumStationStats with 3/15/2018
FROM dbo.SumStationStats('3/15/2018')
ORDER BY RideCount DESC
-- Select all the records from @StationStats
SELECT *
FROM @StationStats
Use SP to DELETE
Create a stored procedure named cuspRideSummaryDelete
in the dbo schema that will delete an existing record in the RideSummary
table and RETURN
the number of rows affected via output parameter.
CREATE PROCEDURE dbo.cuspRideSummaryDelete
-- Specify @DateParm input parameter
(@DateParm date,
-- Specify @RowCountOut output parameter
@RowCountOut INT OUTPUT)
AS
BEGIN
-- Delete record(s) where Date equals @DateParm
DELETE FROM dbo.RideSummary
WHERE DATE = @DateParm
-- Set @RowCountOut to @@ROWCOUNT
SET @RowCountOut = @@ROWCOUNT
END;
Comments
Post a Comment