'随着汇总'sql错误

时间:2013-02-12 12:08:41

标签: sql sql-server sql-server-2005

我正在尝试使用分组编写sql查询,但我收到错误: - 关键字'with'附近的语法不正确。

我写的查询如下: -

SELECT          CONTRACT,  
        PACONTNUMBER,  
        Project Manager ID,  
        Status,  
        Project Type,  
        Project Fee Amount,  
        Forecast Total Cost,  
        Forecast Profit,
        Forecast %,
        Actual Billings,
        Actual Total Cost,
        Current Actual Profit,
        Current %,
        GROUPING(PACONTNUMBER) as PACONTNUMBER,  
        SUM(Project Fee Amount) as Project Fee,
        SUM(Forecast Total Cost) as Forecast Cost,
        SUM(Forecast Profit) as Forecast Profit,
        SUM(Forecast %) as Forecast Percentage,
        SUM(Actual Billings) as Billings Total Actual,
        SUM(Actual Total Cost) as Total Cost Actual
FROM        dbo.vwPAProjects_Summary_New_2
GROUP BY   
        CONTRACT,    
        Project Manager ID,  
        Status,  
        Project Type,  
        Project Fee Amount,  
        Forecast Total Cost,  
        Forecast Profit,
        Forecast %,
        Actual Billings,
        Actual Total Cost,
        Current Actual Profit,
        Current %,
        PACONTNUMBER with rollup 
ORDER BY    GROUPING (PACONTNUMBER)

有人能指出我正确的方向试图让它发挥作用吗?

非常感谢,

1 个答案:

答案 0 :(得分:3)

您的标识符中不能包含空格。对于SQL Server,您可以在方括号[x]中进行环绕,例如:

SELECT          
        CONTRACT,  
        PACONTNUMBER,  
        [Project Manager ID],
        Status,  
        [Project Type],  
        .
        .
        SUM([Actual Total Cost]) as [Total Cost Actual]
FROM        dbo.vwPAProjects_Summary_New_2
GROUP BY   
        CONTRACT,    
        [Project Manager ID],  
        .
        .
        PACONTNUMBER with rollup 
ORDER BY    GROUPING (PACONTNUMBER)