0
Project nr      Task                  Task deadline    Task Type Production
---------------------------------------------------------------------------
456             packed                1 april 2013      Packed
456             Leave production      3 april 2013      Leave Production
456             Flight date           9 april 2013      Flight Date
123             packed                1 april 2013      Packed
123             Leave production      6 april 2013      Leave Production
123             Flight date           9 april 2013      Flight Date
789             packed                1 april 2013      Packed
789             Leave production      9 april 2013      Leave Production
789             Flight date           9 april 2013      Flight Date

我需要一个像上面这样的列表 我想按“停止生产”的日期排序 项目 nr 必须像上面的列表一样保持在 3 组中。

我已经有了这个 SQL。该列表有效,但排序无效。错误是:

无法绑定多部分标识符“任务。[任务期限]”。

我已经有一个建议,但仍然有错误。我如何得到排序?

这是我得到的清单:

Project Nr     Task             TaskDate
0053           Packed           2013-02-05 17:00:00.000
0053           Leave Production 2011-04-26 17:00:00.000
0053           Flight Date      2011-04-22 17:00:00.000
0071           Leave Production 2011-06-24 17:00:00.000
0081           Leave Production 2012-03-09 17:00:00.000
0081-01        Leave Production 2012-03-09 17:00:00.000 

这是 SQL 查询:

SELECT  
    [Project nr], Task, TaskDate
FROM    
    (SELECT   
        MSP_EpmProject_UserView.[Project nr]
        ,MAX(CASE WHEN [Task Type Production] = 'Packed' 
                  THEN [Task deadline] 
             END) AS Packed
        ,MAX(CASE WHEN [Task Type Production] = 'Leave Production' 
                  THEN [Task deadline]
             END) AS [Leave Production]
        ,MAX(CASE WHEN [Task Type Production] = 'Flight Date' 
                  THEN [Task deadline]
             END) AS [Flight Date]
     FROM 
        MSP_EpmProject_UserView 
     LEFT JOIN 
        MSP_EpmTask_UserView ON MSP_EpmProject_UserView.ProjectUID = MSP_EpmTask_UserView.ProjectUID 
     LEFT JOIN 
        MSP_EpmAssignment_UserView ON MSP_EpmTask_UserView.TaskUID = MSP_EpmAssignment_UserView.TaskUID 
     LEFT JOIN 
        MSP_EpmResource_UserView ON MSP_EpmAssignment_UserView.ResourceUID = MSP_EpmResource_UserView.ResourceUID 
     WHERE 
        (MSP_EpmTask_UserView.TaskIsProjectSummary = 0) 
     GROUP BY 
        MSP_EpmProject_UserView.[Project nr]) data
UNPIVOT
    (TaskDate
       FOR [Task] IN ([Pack], [Leave Production], [Flight Date])
    ) piv

此行应该进行排序:

ORDER BY data.[Task deadline]

但我得到一个错误

消息 4104,级别 16,状态 1,第 62 行
无法绑定多部分标识符“data.Taskdeadline”。

4

1 回答 1

0

The subquery that you alias as data just simply isn't returning a column called Taskdeadline

As you can see from your SQL statement - that subquery contains the columns:

[Project nr]
Packed
[Leave Production]
[Flight Date]

but that's all - no Taskdeadline anywhere to be seen....

So therefore, quite obviously, you cannot use that non-existing column in the ORDER BY clause.

于 2013-02-24T14:18:36.630 回答