I have query with a HAVING clause that's not giving the expected result.
The query is below:
SELECT COUNT(ClientProductID), SubCategoryName
FROM v_EnterpriseStructure #
GROUP BY ClientProductID, SubCategoryName Having (PackSizeNum) > 5
And the error I get is below (the HAVING clause is included in the GROUP BY clause, so I don't understand why it would give this error?). Can anyone shed any light, please?
Msg 8121, Level 16, State 1, Line 121 Column 'v_EnterpriseStructure.PackSizeNum' is invalid in the HAVING clause because it is not contained in either an aggregate function or the GROUP BY clause.