SQL如果大小写为true则选择列

时间:2015-08-03 20:16:09

标签: sql-server

我试图弄清楚这个逻辑。我有一些项目数据,我需要编写一个T-SQL语句。

基本上我有人在他们的项目中标记“最终任务”是完整的,但是他们上面的任务不完整所以在执行仪表板中他们将项目显示为完整但是当执行者查看计算时他们看不是100%但可能是90%。显然,人们试图通过将“Go live Complete”任务标记为100%来完成系统游戏。我需要一个查询,以便我可以看到他们是否已将Go live完全标记为100%我需要查看任何其他不是100%的任务。

有一个复杂因素 - 我们有多个项目,所以当我看到任何其他不是100%的任务时,它只需要用于该项目。

这就是我所拥有的:

SELECT 
    CASE 
       WHEN TaskName = 'Go Live Complete' 
            AND TaskPercentCompleted = '100' 
            AND ***'any other tasks are not 100% for that project'*** 
         THEN ***'Show me  the columns below'***
        {ProjectName]
       ,[SMO Programs]
      ,[ProjectUID]
      ,[Project Manager Name]
      ,[TaskUID]
      ,[ParentTaskUID]
      ,[TaskName]
      ,[TaskIndex]
      ,[TaskOutlineLevel]
      ,[Milestone Significance Level]
      ,[TaskOutlineNumber]
      ,[TaskStartDate]
      ,[TaskFinishDate]
      ,[TaskPercentCompleted]
      ,[EPRIDTaskName],
FROM 
    [ProjectWebApp].[dbo].[SMO_ALL_MTP_Tasks]

2 个答案:

答案 0 :(得分:0)

也许这会有用......没有更多信息很难说出来

WITH BADTASKS AS
(
  SELECT ProjctName, TaskName, SMO Programs, ProjectUID, [Project Manager Name], TaskUID, ParentTaskUID, TaskName, TaskIndex, TaskOutlineLevel, [Milestone Significance Level],
         TaskOutlineNumber, TaskStartDate, TaskFinishDate, TaskPercentCompleted, EPRIDTaskName
  FROM ProjectWebApp.dbo.SMO_ALL_MTP_Tasks
  WHERE TaskPercentCompleted != '100'
)
SELECT DONE.TaskName, DONE.TaskPercentCompleted, BADTASKS.*
FROM SMO_ALL_MTP_Tasks DONE
LEFT JOIN BADTASKS ON ALL.ProjectName = BADTASKS.ProjectName
WHERE DONE.TaskName = 'Go Live Complete' AND DONE.TaskPercentCompleted = '100'

答案 1 :(得分:0)

这就是我最终的结果:

   WITH BADTASKS AS
(
  SELECT ProjectName, TaskName, [SMO Programs], [ProjectUID], [Project Manager Name], TaskUID, ParentTaskUID, TaskIndex, TaskOutlineLevel, [Milestone Significance Level],
         TaskOutlineNumber, TaskStartDate, TaskFinishDate, TaskPercentCompleted, EPRIDTaskName, EPRID
  FROM ProjectWebApp.dbo.SMO_ALL_MTP_Tasks
  WHERE TaskPercentCompleted != '100' AND TaskFinishDate < '2015-08-25 23:00:00.000'
)
SELECT DONE.TaskName, DONE.TaskPercentCompleted, BADTASKS.*
FROM ProjectWebApp.dbo.SMO_ALL_MTP_Tasks DONE
inner JOIN BADTASKS ON (
 done.ProjectName = BADTASKS.ProjectName AND
 substring(done.TaskOutlineNumber, 1, len(done.TaskOutlineNumber) - charindex('.', reverse(done.TaskOutlineNumber))) = substring(badTasks.TaskOutlineNumber, 1, len(badtasks.TaskOutlineNumber) - charindex('.', reverse(badtasks.TaskOutlineNumber)))
 )
WHERE DONE.TaskName = 'Go Live Complete' AND DONE.TaskPercentCompleted = '100' AND done.TaskFinishDate < '2015-08-25 23:00:00.000'