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

Connected

Exercise

CREATE FUNCTIONs

Create three functions to help solve the business case:

  1. Convert distance from miles to kilometers.
  2. Convert currency based on exchange rate parameter.
    (These two functions should return a numeric value with precision of 18 and 2 decimal places.)
  3. Identify the driver shift based on the hour parameter value passed.

Instructions 1/3

undefined XP
  • 1

    Use CREATE FUNCTION to accept @Miles input parameter & return the distance converted to kilometers.

  • 2

    Create a function which accepts @DollarAmt and @ExchangeRate input parameters, multiplies them, and returns the result.

  • 3

    Create a function that returns the shift as an integer: 1st shift is 12am to 9am, 2nd is 9am to 5pm, 3rd is 5pm to 12am.