我已經構建了一個select語句來選擇參與者首次記錄在數據庫中的日期。但是我想從這個select語句創建一個函數來使用它。我對SQL相當陌生,以前從未構建函數。我的SELECT語句如下所示:從SQL中的select語句創建函數
Select DATEDIFF(day, (select min(startdatetime)
from GamePlay
), enddatetime)
from GamePlay
where ParticipantID = '200'
我嘗試使用的功能是這樣的:
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
聽起來像是你想要一個存儲過程來代替。 –
我想調用視圖中的函數來創建一個列? – Bradley