Q
Q
Qairat2017-03-16 09:39:24
Stored procedures
Qairat, 2017-03-16 09:39:24

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.

And here is the procedure code:
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

1 answer(s)
K
Konstantin Tsvetkov, 2017-03-16
@Qairat

GROUP BY p.PersonalTypeId;

GROUP BY p.PersonalTypeId, pt.Title

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question