Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Syntax Error - SUM Not Recognized

Author  Topic 

boblarson
Starting Member

17 Posts

Posted - 2008-04-30 : 16:54:06
I'm getting a syntax error that is telling me that SUM is not a recognized function. Any ideas? I know that it should be recognized.

My code is unfinished so maybe that has something to do with it, (I know that I need to still work on replacing the other IIF's (this is a query from Access I am converting to a SP).


CREATE PROCEDURE dbo.sp_JT_BS14_PO_Extract AS
INSERT INTO [temp - buffer sheet - PO] ( weeknum_key, MATERIAL, [bal to be Recvd], PLANT)

SELECT dbo.fnWeeknum_key(DatePart(yyyy,[PLAN_DLVRY_DT]),DatePart(ww,[PLAN_DLVRY_DT])) AS weeknum_key, [base - 7117 PO].MATERIAL,

Sum(Case [FINAL_DELIVERY]
WHEN 'X' THEN '0'
Else [PO_QTY_SIZE]-[RECEIVED_QTY]
End AS [bal to be Recvd]),
[base - 7117 PO].PLANT
FROM [base - 7117 PO]

WHERE ((([base - 7117 PO].PURCH_GRP) In ('120','121')) AND
(([base - 7117 PO].IB_DELIVERY_NO)='0') AND (([base - 7117 PO].SLS_ORG)='1000') AND
(([base - 7117 PO].PO_TYPE) In ('ZP01','ZP02','ZP03','ZP04','ZP06','ZP09')) AND
(([base - 7117 PO].ITEM_CAT)='0') AND
(([base - 7117 PO].DELETION_FLG)<>'L')) OR ((([base - 7117 PO].PURCH_GRP) In ('130','131')) AND (([base - 7117 PO].IB_DELIVERY_NO)='0') AND
(([base - 7117 PO].PO_TYPE) In ('ZP01','ZP02','ZP03','ZP04','ZP06','ZP09')) AND
(([base - 7117 PO].ITEM_CAT)='0') AND (([base - 7117 PO].DELETION_FLG)<>'L'))

GROUP BY dbo.fnWeeknum_key(DatePart(yyyy,[PLAN_DLVRY_DT]),DatePart(ww,[PLAN_DLVRY_DT])), [base - 7117 PO].MATERIAL, [base - 7117 PO].PLANT

HAVING (((Sum(IIf([FINAL_DELIVERY]='X',0,[PO_QTY_SIZE]-[RECEIVED_QTY])))>0) AND (([base - 7117 PO].PLANT)='1051')) OR
(((Sum(IIf([FINAL_DELIVERY]='X',0,[PO_QTY_SIZE]-[RECEIVED_QTY])))>0) AND (([base - 7117 PO].PLANT)='1060'));



Thanks,

Bob Larson

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-30 : 16:57:04
Sum(Case [FINAL_DELIVERY]
WHEN 'X' THEN '0'
Else [PO_QTY_SIZE]-[RECEIVED_QTY]
End ) AS [bal to be Recvd]

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

boblarson
Starting Member

17 Posts

Posted - 2008-04-30 : 17:01:38
Fantastic Tara! Thanks a bunch. I'm so used to Access syntax that it is taking a little bit to get to know where to put all of the parens, commas, etc. It worked great.


Thanks,

Bob Larson
Go to Top of Page
   

- Advertisement -