1. Learn
  2. /
  3. Courses
  4. /
  5. Writing Functions and Stored Procedures in SQL Server

Connected

Exercise

Mean imputation

Create a stored procedure that will apply mean imputation to the YellowTripData records with an incorrect TripDistance of zero. The average trip distance variable should have a precision of 18 and 4 decimal places.

Instructions

100 XP
  • Create a stored procedure named cuspImputeTripDistanceMean
  • Create a numeric variable: @AvgTripDistance.
  • Compute the average TripDistance for all records where TripDistance is greater than 0.
  • Update the records in YellowTripData where TripDistance is 0 and set to @AvgTripDistance.