SQL Server错误102“附近的语法不正确”

时间:2022-06-24 01:38:13

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

2 个解决方案

#1


0  

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.

在开始时缺少一个CASE,最后似乎有一个胭脂括号。

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, 

#2


0  

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.

要获取完整的错误消息,请将SQL代码复制到SQL Server Management Studio中。选择所需的数据库并运行它。如果任何字符出现问题,它将在“消息”选项卡中显示如下。

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.

如果仍然很难说,您可以双击错误,它将带您到错误的代码行。

#1


0  

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.

在开始时缺少一个CASE,最后似乎有一个胭脂括号。

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, 

#2


0  

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.

要获取完整的错误消息,请将SQL代码复制到SQL Server Management Studio中。选择所需的数据库并运行它。如果任何字符出现问题,它将在“消息”选项卡中显示如下。

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.

如果仍然很难说,您可以双击错误,它将带您到错误的代码行。