CREATE FUNCTION Movies.ReturnNumberOfCopies(@IDMovies INT)
RETURNS INT
AS
BEGIN
DECLARE @NumberOfCopiesIfMovieExists INT;
SELECT @NumberOfCopiesIfMovieExists = Movis.NumberOfCopies
FROM Movies
WHERE Movies.IDMovies = @IDMovies;
RETURN IsNull(@NumberOfCopiesIfMovieExists, 0);
END
Be aware that the performance of multi-statement user-defined functions is not great.