Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

An aggregate cannot appear in an ON clause unless it is in a subquery

$
0
0

I am getting the following error on the query copied below:

"An aggregate cannot appear in an ON clause unless it is in a subquery contained in a HAVING clause or select list, and the column being aggregated is an outer reference."

Since there is no 1 to 1 join on d.VCMN and h.VDMN, I want to join on d.VCMN <= max(h.VDMN) for that h.P_ID, b.S_U_ID

How do i set up a sql for this situation?

   Select distinct H.P_ID,  B.S_U_ID,  H.vdmn,  D.VCMN as VCMN _d,  C.I_A_ID,   D.I_A_V_ID
   From PSH H
   left join PSU B on h.SH_ID = B.SH_ID
   left join PPA C on b.UA_ID = C.PA_ID
   left join PIA_V D on c.IIA_ID = d.IA_ID
                                       and D.VCMN <=max(H.VDMN)



Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>