Answer the question
In order to leave comments, you need to log in
How to fix an error in an MsSQl procedure?
Hi all!
I can't figure out the error I get
this error:
Столбец "PersonalType.Title" недопустим в списке выбора, поскольку он не содержится ни в агрегатной функции, ни в предложении GROUP BY.
CREATE PROCEDURE GetObjectPersonalAnalysis
@ObjectId BIGINT
AS
BEGIN
SELECT
p.PersonalTypeId,
pt.Title,
SUM(p.Fact) as Fact,
SUM(p.[Plan]) as [Plan],
( SUM(p.[Plan]) - SUM(p.Fact) ) as Deficit,
(
CASE
WHEN SUM(p.Fact) > SUM(p.[Plan]) THEN ((SUM(p.[Plan])) / (SUM(p.Fact))) * 100
WHEN SUM(p.Fact) < SUM(p.[Plan]) THEN ((SUM(p.Fact)) / (SUM(p.[Plan]))) * 100
ELSE 100
END
) as MAPPING
FROM Personals p
JOIN PersonalType pt
ON p.PersonalTypeId = pt.Id
WHERE (p.OrganizationDepartmentId = @ObjectId ) OR (p.OrganizationId = @ObjectId AND (p.OrganizationDepartmentId = 0 OR @ObjectId IS NULL))
GROUP BY p.PersonalTypeId;
END
Answer the question
In order to leave comments, you need to log in
GROUP BY p.PersonalTypeId;
GROUP BY p.PersonalTypeId, pt.Title
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question