I was curious if anyone has written a BAQ they’re willing to share that has a "HAVING’ statement in the execution statement. A co-worker pointed out this statement in SQL to me yesterday, but when I attempted to implement in an Epicor BAQ it doesn’t behave quite as expected (I receive a grouping error).
The goal of the query is to first count all the instances of part lots, and then filter down the results to only those that have more than one instance. Essentially trying to only display duplicate part lots (in different bins).
When adding the ‘having’ statement ,Count(PartBin_PartNum) > 1, the BAQ displays the error:
‘SubQuery1.PartBin_LotNum’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Even though the PartNum_LotNum field has been grouped in the BAQ.
You might be better off doing a count over partition to get the counts, then you can filter by the count later. If you do it this way, you can leave the detail in the rows.
Also, to get this to work, you need the PartBin.Lotnum, not PartNum.Lotnum. Which table (or subquery) it comes from is important too. You generally will have duplicate information/columns in the BAQ, but you can hide that in the dashboard.
But the error says is missing that field from your subquery specifically. So even if you have the database table on that level, you have to include the field from the subquery.
Add the PartBin.LotNum from Subquery1 to your top level, and it will work. Edit I didn’t realize you were trying to add the having in the execution parameter.
edit
So I opened up the query and I see what you are trying to do now. The “having” is used with subquery criteria. I don’t think you can add it in the way you were trying to do it.
select
[PartBin].[LotNum] as [PartBin_LotNum],
[PartBin].[PartNum] as [PartBin_PartNum],
(count(PartBin.PartNum)) as [Calculated_couting]
from Erp.PartBin as PartBin
group by [PartBin].[LotNum],
[PartBin].[PartNum]
having (count(PartBin.PartNum)) > 1