I wanted to be able to grab related APVM.Name
data from this query however I get the error:
"Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."
When I add APVM.Name
to the GROUP BY
clause, the data starts to lose its accuracy. How can I get the APVM.Name
data without this error? Thank you in advance!
SELECT
bSLHD.SL as [SL],
APVM.Vendor as [Vendor Number],
bSLHD.Job as [Job Number],
JCCM.Department,
APVM.Name
FROM
bSLHD
INNER JOIN SLCT ON
bSLHD.SL = SLCT.SL
AND
bSLHD.VendorGroup = SLCT.VendorGroup
AND
bSLHD.Vendor = SLCT.Vendor
AND
bSLHD.SLCo = SLCT.SLCo
INNER JOIN APVM ON bSLHD.Vendor = APVM.Vendor
INNER JOIN JCCM ON bSLHD.Job = JCCM.Contract AND bSLHD.JCCo = JCCM.JCCo
WHERE
JCCM.Department = '10'
GROUP BY
bSLHD.SL,
APVM.Vendor,
bSLHD.Job,
JCCM.Department
HAVING
SUM(CASE WHEN SLCT.CompCode = 'LI' THEN 1 ELSE 0 END) = 0
ORDER BY
bSLHD.SL