I'm trying to create a function that SUMs the total number of minutes of actual duration for videos with a Finished status given a UserID as a parameter. This is what I have so far but I can't figure out how to add the parameter for the Finished status. This comes from a different table of Status that has a StatusID and StatusText. Or would I do a NOT NULL statement?
CREATE OR ALTER FUNCTION dbo.vc_VideoDuration(@userID int)
RETURNS int AS BEGIN DECLARE @returnValue int
SELECT @returnValue = DATEDIFF (n, StartDateTime, EndDateTime) FROM vc_Video
WHERE vc_Video.vc_UserID = @userID
RETURN @returnValue
END
GO