I am creating a function so I can take the results of my select statement and place them in a view within our database. My SELECT statement returns one result when I run it, but when I go and place it in to create a function I get the error:
Only one expression can be specified in the select list when the
subquery is not introduced with EXISTS.
I am still new and learning and would appreciate any help in what I am doing wrong.
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