We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
I am having trouble getting the aggregation to work in the statement below. Am I missing something with this logic. Your help is greatly appreciated.
(SELECT cmp_id from stops s (nolock) where s.ord_hdrnumber = o.ord_hdrnumber and s.stp_event in ('LUL','LLD','DRL', 'HPL') and s.stp_sequence = MAX(s.stp_sequence)) as ReceiverID
Error Message: An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference.
Solved! Go to Solution.
Hi @cheid_4838 ,
It looks like you're running into an issue with using an aggregate function ('MAX()') directly in the 'WHERE' clause, which is not permitted in SQL. Please update your SQL statement as below and check if it can work or not...
SELECT s.cmp_id AS ReceiverID
FROM stops s (nolock)
JOIN (
SELECT ord_hdrnumber, MAX(stp_sequence) AS max_sequence
FROM stops
WHERE stp_event IN ('LUL', 'LLD', 'DRL', 'HPL')
GROUP BY ord_hdrnumber
) max_stops
ON s.ord_hdrnumber = max_stops.ord_hdrnumber
AND s.stp_sequence = max_stops.max_sequence
Best Regards
Error Aggregation Handler (EAH) - 7F2F
Hi @cheid_4838 ,
It looks like you're running into an issue with using an aggregate function ('MAX()') directly in the 'WHERE' clause, which is not permitted in SQL. Please update your SQL statement as below and check if it can work or not...
SELECT s.cmp_id AS ReceiverID
FROM stops s (nolock)
JOIN (
SELECT ord_hdrnumber, MAX(stp_sequence) AS max_sequence
FROM stops
WHERE stp_event IN ('LUL', 'LLD', 'DRL', 'HPL')
GROUP BY ord_hdrnumber
) max_stops
ON s.ord_hdrnumber = max_stops.ord_hdrnumber
AND s.stp_sequence = max_stops.max_sequence
Best Regards
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |