0

我正在尝试编写带有分组的 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)

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

非常感谢,

4

1 回答 1

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)
于 2013-02-12T12:16:16.793 回答