LISTING 3: The dbo.fn_cast9() Function Implemented with a Mathematical Computation ALTER FUNCTION dbo.fn_cast9(@num AS int) RETURNS int AS BEGIN IF @num < 0 OR @num IS NULL RETURN NULL RETURN @num * 10 + (@num - 1) % 9 + 1 END