bustercoder
Programmer
- Mar 13, 2007
- 96
Hello, I'm trying to run this update (testing with the select statement first) with a group by and keep getting "An aggregate may not appear in the set list of an UPDATE statement":
An aggregate may not appear in the set list of an UPDATE statement:
update SY00500 set NUMOFTRX = count (SOP10100.SOPNUMBE), BCHTOTAL = sum(DOCAMNT)
--SELECT count (SOP10100.SOPNUMBE), BCHTOTAL = isnull(sum(DOCAMNT),0),SOP10100.BACHNUMB, COUNT(*) AS Expr1, SY00500.BCHSOURC, SY00500.NUMOFTRX, SY00500.BCHTOTAL, SY00500.BACHNUMB AS Expr2
FROM SOP10100 RIGHT OUTER JOIN
SY00500 ON SOP10100.BCHSOURC = SY00500.BCHSOURC AND SOP10100.BACHNUMB = SY00500.BACHNUMB
GROUP BY SOP10100.BACHNUMB, SY00500.BCHSOURC, SY00500.NUMOFTRX, SY00500.BCHTOTAL, SY00500.BACHNUMB
HAVING (SY00500.BCHSOURC = 'sales entry')
I've tried to nest the select and use an outer grouping, but I'm not having any success. Could someone please show me the best approach?
Thanks,
Buster
An aggregate may not appear in the set list of an UPDATE statement:
update SY00500 set NUMOFTRX = count (SOP10100.SOPNUMBE), BCHTOTAL = sum(DOCAMNT)
--SELECT count (SOP10100.SOPNUMBE), BCHTOTAL = isnull(sum(DOCAMNT),0),SOP10100.BACHNUMB, COUNT(*) AS Expr1, SY00500.BCHSOURC, SY00500.NUMOFTRX, SY00500.BCHTOTAL, SY00500.BACHNUMB AS Expr2
FROM SOP10100 RIGHT OUTER JOIN
SY00500 ON SOP10100.BCHSOURC = SY00500.BCHSOURC AND SOP10100.BACHNUMB = SY00500.BACHNUMB
GROUP BY SOP10100.BACHNUMB, SY00500.BCHSOURC, SY00500.NUMOFTRX, SY00500.BCHTOTAL, SY00500.BACHNUMB
HAVING (SY00500.BCHSOURC = 'sales entry')
I've tried to nest the select and use an outer grouping, but I'm not having any success. Could someone please show me the best approach?
Thanks,
Buster