I have built a select statement to pick the date the participant was first recorded in the database. However I want to create a function out of this select statement to use it. I am fairly new to SQL and have never built a function before. My select statement looks like this:
Select DATEDIFF(day, (select min(startdatetime)
from GamePlay
), enddatetime)
from GamePlay
where ParticipantID = '200'
My attempted function looks like this:
CREATE FUNCTION daysPlayed (@ParticipantID int)
RETURNS DateTime
AS
BEGIN
Return DATEDIFF(day, (select min(startdatetime)
from GamePlay
), enddatetime)
from GamePlay
where ParticipantID = @ParticipantID
END
GO