kalbal
asked on
SQL Server syntax error message ('INCORRECT SYNTAX NEAR =') in a query
hi, i am trying to run the following query in SQL Server 2005 Express SSME. It keeps giving me error "Syntax error near =" in the CASE statement (which is in the WHERE clause). I dont understand why...
I know it must be something pretty simple, but i cant understand what. I need ti urgently and so am offering 500points here.
Let me know if you need more info plss..
I know it must be something pretty simple, but i cant understand what. I need ti urgently and so am offering 500points here.
Let me know if you need more info plss..
SELECT ACCOUNTS.AccountLevel, ACCOUNTS.AccountName, SALESHEADER.OrderDate, SALESHEADER.DeliveryDate, SALESHEADER.SalesHDRID,
SALESHEADER.PrivateOrderNumber, Sum(CASE WHEN (SALESDETAIL.PackerID Is Not Null And SALESDETAIL.PackerTime Is Not Null Or
SALESDETAIL.Quantity Is Null Or SALESDETAIL.Quantity=0) THEN 0 ELSE 1 END) AS [Left], Sum((CASE WHEN ([SALESDETAIL].[CheckerID] Is Not Null
And [SALESDETAIL].[CheckerTime] Is Not Null Or [SALESDETAIL].[Quantity] Is Null Or [SALESDETAIL].[Quantity]=0) THEN 0 ELSE 1 END)) AS NotChecked
FROM ITEMS INNER JOIN (ACCOUNTS INNER JOIN (SALESHEADER INNER JOIN SALESDETAIL ON SALESHEADER.SalesHDRID = SALESDETAIL.SalesHDRID)
ON ACCOUNTS.AccountID = SALESHEADER.AccountID) ON ITEMS.ItemID = SALESDETAIL.ItemID
WHERE (CASE WHEN ACCOUNTS.DeliveryAccountID Is Null THEN (ACCOUNTS.ParentAccountID = 8322) ELSE (ACCOUNTS.DeliveryAccountID = 8322) END)
and SALESHEADER.InvoiceStatusID = 'OR'
GROUP BY SALESHEADER.AccountID, ACCOUNTS.AccountLevel, ACCOUNTS.AccountName, SALESHEADER.OrderDate, SALESHEADER.DeliveryDate,
SALESHEADER.SalesHDRID, SALESHEADER.PrivateOrderNumber, SALESHEADER.InvoiceStatusID, SALESHEADER.OrderComment
ORDER BY SALESHEADER.DeliveryDate, ACCOUNTS.AccountName
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
note: please check out your SUM(CASE ...) statements, you mix AND and OR conditions without () , that will give you wrong results.