我正在創建一個函數,以便我可以將選擇語句的結果放入數據庫的視圖中。我的SELECT語句返回一個結果,當我運行它,但是當我去,並將其放置在創建一個功能我得到的錯誤:創建函數SQL Server 2012時出錯
Only one expression can be specified in the select list when the
subquery is not introduced with EXISTS.
我仍然新和學習,並希望在什麼我任何幫助做錯了。
CREATE FUNCTION CXi_Application
@Application nvarchar(255), @Wave nvarchar(255)
RETURNS int
AS
BEGIN
DECLARE @Return int
SET @Return =
(SELECT @Application, (
(sum(CASE WHEN overall_score IN (1) THEN 1 ELSE 0 END) + sum(CASE WHEN effective_score IN (1) THEN 1 ELSE 0 END) + sum(CASE WHEN easeuse_score IN (1) THEN 1 ELSE 0 END)) +
(sum(CASE WHEN overall_score IN (2) THEN 2 ELSE 0 END) + sum(CASE WHEN effective_score IN (2) THEN 2 ELSE 0 END) + sum(CASE WHEN easeuse_score IN (2) THEN 2 ELSE 0 END)) +
(sum(CASE WHEN overall_score IN (3) THEN 3 ELSE 0 END) + sum(CASE WHEN effective_score IN (3) THEN 3 ELSE 0 END) + sum(CASE WHEN easeuse_score IN (3) THEN 3 ELSE 0 END)) +
(sum(CASE WHEN overall_score IN (4) THEN 4 ELSE 0 END) + sum(CASE WHEN effective_score IN (4) THEN 4 ELSE 0 END) + sum(CASE WHEN easeuse_score IN (4) THEN 4 ELSE 0 END)) +
(sum(CASE WHEN overall_score IN (5) THEN 5 ELSE 0 END) + sum(CASE WHEN effective_score IN (5) THEN 5 ELSE 0 END) + sum(CASE WHEN easeuse_score IN (5) THEN 5 ELSE 0 END)))/
(count(overall_score) + count(effective_score) + count(easeuse_score) * 1.00)
FROM FY14_DataMerge
WHERE [Status] = 'Completed' AND [Application] = @Application AND [Wave] = @Wave);
-- Return the result of the function
RETURN @Return
END
GO
的錯誤是不言自明的。運行您的'SELECT'語句並查看它輸出的列數。你只能有一個。 – Kermit
是的,我現在看到了。謝謝你幫助我。 :) –