It's just telling me there is an error near ". Any help? Does that mean the problem is near a space? I've seen other people have similar problems with their error near '<' or ';'but not just ".
SELECT CO.JCCo, CO.Contract, CO.PCO AS PCO, CO.PCOType, MAX(CO.COStatus) AS Status, MAX(CO.COApprovedYN) AS Approved,
SUM(CO.COContPendAmt) AS PriceAmount,
SUM(CO.COCostDollars) AS CostAmount,
SUM(CO.COContPendAmt) - SUM(CO.COCostDollars) AS CO_Profit,
PMOP.Description, PMOP.PendingStatus, MAX(PMOP.DateCreated) AS PODate, GETDATE() AS Today, DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE()) AS DaysOutstanding, (CASE WHEN (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) < 30 THEN 'Less than 30'
WHEN (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) > 30 AND (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) <= 60 THEN ' 30 - 60 ' WHEN (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) > 60 AND (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) <= 90 THEN ' 60 - 90 '
WHEN (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) > 90 THEN ' Over 90 ' ELSE 'Less than 30' END) AS AgingCategory,
PMOI.FixedAmount AS FixedAmount, PMOI.PendingAmount AS PendingAmount, PMOI.PCOItem,
(SELECT JCJM.ProjectMgr FROM JCJM WHERE JCJM.Job = CO.Contract AND JCJM.JCCo = 1) AS ProjectManager
FROM brvJCCostRevChgOrders AS CO
RIGHT JOIN PMOP ON CO.PCOType = PMOP.PCOType AND CO.PCO = PMOP.PCO AND CO.Contract = PMOP.Contract
RIGHT JOIN PMOI ON PMOP.PCOType = PMOI.PCOType AND PMOP.PCO = PMOI.PCO AND PMOP.Project = PMOI.Project
WHERE (PMOP.PendingStatus = 0) AND (CO.JCCo = 1) AND PMOP.Status <> 'VOID' AND PMOI.PMCo = 1 AND PMOP.PMCo = 1 AND (SELECT JCJM.ProjectMgr FROM JCJM WHERE JCJM.Job = CO.Contract AND JCJM.JCCo = 1) IS NOT NULL
GROUP BY CO.JCCo, CO.Contract, CO.PCO, PMOP.Description, CO.PCOType, PMOP.PendingStatus, PMOI.PCOItem, PMOI.FixedAmount, PMOI.PendingAmount
ORDER BY CO.Contract, CO.PCOType
This part....
WHEN (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) > 30 AND (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) <= 60 THEN ' 30 - 60 ' WHEN (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) > 60 AND (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) <= 90 THEN ' 60 - 90 '
WHEN (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) > 90 THEN ' Over 90 ' ELSE 'Less than 30' END) AS AgingCategory,
is missing a CASE
at the beginning and seemingly has a rouge parentheses at the end.
Here is the corrected version:
CASE
WHEN (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) > 30 AND (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) <= 60
THEN ' 30 - 60 ',
WHEN (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) > 60 AND (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) <= 90
THEN ' 60 - 90 ',
WHEN (DATEDIFF(d, MAX(PMOP.DateCreated), GETDATE())) > 90
THEN ' Over 90 '
ELSE 'Less than 30'
END AS AgingCategory,
To get the full error message, copy your SQL code into SQL Server Management studio. Select the database you need and run it. If there is a problem with any character, it will show you below in the Messages tab.
If it's still hard to tell, you can double click the error and it will take you to the line of the code with the error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.