Get startedGet started for free

Hot Deck imputation

Create a function named dbo.GetTripDistanceHotDeck that returns a TripDistance value via Hot Deck methodology. TripDistance should have a precision of 18 and 4 decimal places.

This exercise is part of the course

Writing Functions and Stored Procedures in SQL Server

View Course

Exercise instructions

  • Create a function named dbo.GetTripDistanceHotDeck() that returns a numeric data type.
  • Select the first TripDistance value from YellowTripData sample of 1000 records.
  • The sample of 1000 records should only include those where TripDistance is more than zero.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

-- Create the function
___ ___ ___.___()
-- Specify return data type
___ ___(18,4)
AS 
BEGIN
RETURN
	-- Select the first TripDistance value
	(___ TOP 1 ___
	FROM YellowTripData
    -- Sample 1000 records
	TABLESAMPLE(1000 rows)
    -- Only include records where TripDistance is > 0
	___ ___ ___ ___)
END;
Edit and Run Code