﻿ALTER PROCEDURE [dbo].[ProjectSchedule] 

   @EProjectId VARCHAR(50)  

AS	
/*********首页Schedule第一部分**********/
SELECT 1 AS id,
 'Job Receive' AS MileSones,
'N.A' AS Schedule,
(CASE WHEN CONVERT(VARCHAR(10),PM_MA_JobReveive, 23) IS NOT NULL THEN CONVERT(VARCHAR(10),PM_MA_JobReveive, 23) ELSE 'N.A' END) AS Actual
FROM dbo.Editor_EProject AS eProject
WHERE eProject.EProjectId=@EProjectId

UNION
SELECT 2 AS id,
'Planning Cost Approval' AS MileSones,
 'N.A' AS Schedule,
(CASE WHEN CONVERT(VARCHAR(10),PM_Planning_Approval, 23) IS NOT NULL THEN CONVERT(VARCHAR(10),PM_Planning_Approval, 23) ELSE 'N.A' END) AS Actual
FROM dbo.Editor_EProject AS eProject
WHERE eProject.EProjectId=@EProjectId
--(CASE WHEN CONVERT(VARCHAR(10),eProject.ProjectControl_MS_ResourcePlanReceived,23) IS NOT NULL 
--THEN CONVERT(VARCHAR(10),eProject.ProjectControl_MS_ResourcePlanReceived,23) ELSE 'N.A' END) AS Actual
--FROM dbo.Editor_EProject AS eProject
--WHERE eProject.EProjectId=@EProjectId

UNION
SELECT 3 AS id,
 'Pre-approval' AS MileSones,
'N.A' AS Schedule,
(CASE WHEN CONVERT(VARCHAR(10),PM_Pre_Approval, 23) IS NOT NULL THEN CONVERT(VARCHAR(10),PM_Pre_Approval, 23) ELSE 'N.A' END) AS Actual
FROM dbo.Editor_EProject AS eProject
WHERE eProject.EProjectId=@EProjectId

UNION

SELECT 4 AS id,
'Kick-off Meeting' AS MileSones,
'N.A' AS Schedule,
(CASE WHEN CONVERT(VARCHAR(10), PM_MA_KickOffMeeting, 23) IS NOT NULL THEN CONVERT(VARCHAR(10), PM_MA_KickOffMeeting, 23) ELSE 'N.A' END) AS Actual
FROM dbo.Editor_EProject AS eProject
WHERE eProject.EProjectId=@EProjectId

UNION 

SELECT 5 AS id,
'SR1/2' AS MileSones,
(CASE WHEN CONVERT(VARCHAR(10), ProjectControl_MS_SR, 23) IS NOT NULL THEN CONVERT(VARCHAR(10), ProjectControl_MS_SR, 23) ELSE 'N.A' END) AS Schedule,
(CASE WHEN CONVERT(VARCHAR(10), PM_MA_SR, 23) IS NOT NULL THEN CONVERT(VARCHAR(10), PM_MA_SR, 23) ELSE 'N.A' END) AS Actual
FROM dbo.Editor_EProject AS eProject
WHERE eProject.EProjectId=@EProjectId

UNION 

SELECT 6 AS id,
'Final Approval' AS MileSones,
(CASE WHEN CONVERT(VARCHAR(10), ProjectControl_MS_Approval, 23) IS NOT NULL THEN CONVERT(VARCHAR(10), ProjectControl_MS_Approval, 23) ELSE 'N.A' END) AS Schedule,
(CASE WHEN CONVERT(VARCHAR(10), PM_MA_ProjectApproval, 23) IS NOT NULL THEN CONVERT(VARCHAR(10), PM_MA_ProjectApproval, 23) ELSE 'N.A' END) AS Actual
FROM dbo.Editor_EProject AS eProject
WHERE eProject.EProjectId=@EProjectId

UNION

SELECT 7 AS id,
 'MC' AS MileSones,
(CASE WHEN CONVERT(VARCHAR(10), ProjectControl_Revised_MC_Date, 23) IS NOT NULL AND ProjectControl_Revised_MC_Date=ProjectControl_MS_MC
 THEN CONVERT(VARCHAR(10), ProjectControl_Revised_MC_Date, 23) 
 ELSE CASE WHEN CONVERT(VARCHAR(10), ProjectControl_Revised_MC_Date, 23) IS NOT NULL AND ProjectControl_Revised_MC_Date!=ProjectControl_MS_MC
 THEN CONVERT(VARCHAR(10), ProjectControl_Revised_MC_Date, 23)+'*'
 ELSE 'N.A' END END)  AS Schedule,
(CASE WHEN CONVERT(VARCHAR(10), CM_MA_MC, 23) IS NOT NULL THEN CONVERT(VARCHAR(10), CM_MA_MC, 23)ELSE 'N.A' END)AS Actual
FROM dbo.Editor_EProject AS eProject
WHERE eProject.EProjectId=@EProjectId

UNION

SELECT 8 AS id,
'Close' AS MileSones,
(CASE WHEN CONVERT(VARCHAR(10), ProjectControl_MS_Close, 23) IS NOT NULL THEN CONVERT(VARCHAR(10), ProjectControl_MS_Close, 23) ELSE 'N.A' END) AS Schedule,
(CASE WHEN CONVERT(VARCHAR(10), ProjectControl_ClosedDate, 23) IS NOT NULL THEN CONVERT(VARCHAR(10), ProjectControl_ClosedDate, 23) ELSE 'N.A' END)as Actual

FROM dbo.Editor_EProject AS eProject
WHERE eProject.EProjectId=@EProjectId 

UNION

SELECT 9 AS id,
'Cancel' AS MileSones,
(CASE WHEN CONVERT(VARCHAR(10), ProjectControl_PC_CancelDate, 23) IS NOT NULL THEN CONVERT(VARCHAR(10), ProjectControl_PC_CancelDate, 23) ELSE 'N.A' END) AS Schedule,
'N.A' AS Actual
FROM dbo.Editor_EProject AS eProject
WHERE eProject.EProjectId=@EProjectId

GO

