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 2005 Forums
 Transact-SQL (2005)
 CASE Statement Syntax Error

Author  Topic 

lueylump
Starting Member

25 Posts

Posted - 2010-12-08 : 13:36:37
I am getting the following syntax error that I can't seem to figure out:

Msg 102, Level 15, State 1, Line 19
Incorrect syntax near 'SUM'.

Go 

Declare @Previous_Start_Date datetime,
@Previous_End_Date datetime,
@Current_Start_Date datetime,
@Current_End_Date datetime

Set @Previous_Start_Date = '20080701'
Set @Previous_End_Date = '20080630 23:59:59'
Set @Current_Start_Date = '20090701'
Set @Current_End_Date = '20100630 23:59:59'

SELECT Count(*) AS Total_Donors,

SUM(CASE WHEN SUM(H.Batch_Amount) > 0 and SUM(I.Batch_Amount) > 0 Then 1 ELSE NULL END) as Return_Donors
SUM(CASE WHEN SUM(H.Batch_Amount) = 0 and SUM(I.Batch_Amount) > 0 Then 1 ELSE NULL END) as Lapsed_Donors

FROM Per_Group_Loc A
INNER JOIN Payment_Device B ON B.Payor_Code = A.Group_Code
INNER JOIN Payment_Device_History C ON C.Pay_Device_ID = B.Pay_Device_ID
INNER JOIN Payment D ON D.Payment_ID = C.Payment_ID
INNER JOIN Payment_Allocation F ON F.Payment_ID = D.Payment_ID
INNER JOIN Payment_Batch H ON H.Batch_ID = D.Batch_ID and H.Process_Date between @Previous_Start_Date and @Previous_End_Date
INNER JOIN Payment_Batch I ON I.Batch_ID = D.Batch_ID and I.Process_Date between @Current_Start_Date and @Current_End_Date
INNER JOIN LookUpValues E ON E.LUV_ID = A.Group_Type_Code
INNER JOIN Org_Addresses G ON G.Org_Addr_ID = A.Primary_Mail_Addr_ID

WHERE F.Allocation_Amt > 0 AND
A.Create_Date < @Current_Start_Date AND
F.Fund_ID NOT IN('92F34AC0-C5CE-454D-A553-3BB6C6AA8E65','A2222598-D018-4F58-A68B-604E4D292A57',
'9D91E0EF-6773-4E47-9573-6901136B2FFF','84F2C1BF-2ACE-4959-8FB1-76BE75518FE7','8DD4BAFF-FF3A-420C-933A-7810F2EDC296',
'D1393F1C-4A44-4E3D-9820-7A57EF2C0771','F51C37E6-927E-4F1F-B900-87EBC4417209','CBF486D6-D184-4890-8F2F-DB8AEDF8DA81',
'75FED8FF-E146-4B0C-B7EC-516D38AADE74')

GROUP BY A.Group_Formal_Name
ORDER BY A.Group_Formal_Name


Any assistance is greatly appreciated.

Phil

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-12-08 : 13:44:53
There is a comma missing after "as Return_Donors"


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-12-08 : 13:45:13
you're missing a comma after this line:
SUM(CASE WHEN SUM(H.Batch_Amount) > 0 and SUM(I.Batch_Amount) > 0 Then 1 ELSE NULL END) as Return_Donors

Go to Top of Page

lueylump
Starting Member

25 Posts

Posted - 2010-12-08 : 13:47:22
Thank YOU!!!
Go to Top of Page
   

- Advertisement -