I am running the below SQL but keep getting the error:-
‘Column ‘SRVS.dbo.BTQGLDistributionsWithProjectCodesHM.AccountNo’ is invalid in the select list because it is not contained in either an
aggregate function or the GROUP BY clause.
The code I am running is:-
SELECT AccountNo,
TransDate,
JournalNo,
AuditTrail,
Description,
JnlAmount,
ACTINDX,
CONTRACTNAME,
PAPROJNUMBER,GROUPING(PAPROJNUMBER) as PAPROJNUMBER,
SUM(PAFeebillamount) as total
FROM SRVS.dbo.BTQGLDistributionsWithProjectCodesHM
GROUP BY PAPROJNUMBER with rollup
ORDER BY GROUPING (PAPROJNUMBER
Can anyone point me in the correct direction on this?
When using a
GROUP BYstatement, anything not using an aggregate must be specified in thegroup byclause.