Hello
apologies but will try and be as detailed as possible .
- I have 3 Columns to return
MilestoneBaselineDate
MilestoneForecastDate
Milestone Variance (Days)
-
I need Milestone Variance (Days) to return INT
-
the sql variant code you provided is what I am now using and as I said earlier , its now giving me the result I want in days (datatype INT) but NOT for all rows
-
as you can see from the 4 rows I have provided I expect 0days in the last Column (Milestone Variance )
(My Apologies , the original above was wrong thats why you couldn't understand .
1.as you can see below the Baseline dates and Actual Forecast are same dates so a subtraction should give zero for all rows
- the last row also should be zero but giving -212 . this is wrong
Baseline. Forecast Variance in Days
2011-06-01:00:00:00:000. 2011-06-01:00:00:000. 2010-06-01:00:00:000.
2011-06-30:00:00:00:000. 2011-06-30:00:00:000. 2010-06-30:00:00:000.
2010-10-01:00:00:00:000. 2010-10-01:00:00:000. 0
2012-03-31:00:00:00:000. 2012-03-31:00:00:000. -212
here's the Code am using now. putting all the code here . ive outlined the part am having the issue with . other than that the main query runs OK .
SELECT
[vwProject - Last QTR].ProjReturnID,
[vwProject - Last QTR].ProjectID,
[vwProject - Last QTR].[ID Number],
Key_Match.IDQ, Key_Match.[Qtr Name] AS Quarter,
[vwProject - Last QTR].Department,
[vwProject - Last QTR].ProjectName AS [Project Name - Most Recent],
Milestone.MilestoneDesc AS [Milestone - Name],
vwMilestoneTypeNewOld.CurrentName AS [Milestone - Type],
Milestone.[Version No] AS [Milestone - Version Number],
--IIf([LatestBaselineDate] Is Null,[OriginalBaselineDate],[LatestBaselineDate]) AS [Milestone - Baseline Date],
--Milestone.[Actual-ForecastDate] AS [Milestone - Forecast Date], [Actual-ForecastDate]-
--(IIf([LatestBaselineDate] Is Null,[OriginalBaselineDate],[LatestBaselineDate])) AS [Milestone - Variance (Days)],
--Milestone.Status AS [Milestone - Status], Milestone.MilestoneNotes AS [Milestone - Comments], Milestone.Source AS [Milestone - Category], Milestone.[Critical Path] AS [Delivery Critical Path]
CASE
WHEN [LatestBaselineDate] Is Null THEN [OriginalBaselineDate] ELSE [LatestBaselineDate]
END
AS [Milestone - Baseline Date], Milestone.[Actual-ForecastDate] AS [Milestone - Forecast Date],
[Actual-ForecastDate],
CASE
WHEN [LatestBaselineDate] Is Null THEN Cast( [OriginalBaselineDate] as sql_variant)
ELSE
Cast( Datediff(dd,[Actual-ForecastDate],[OriginalBaselineDate])as sql_variant)
END
AS [Milestone - Variance (Days)],
Milestone.Status AS [Milestone - Status],
Milestone.MilestoneNotes AS [Milestone - Comments],
Milestone.Source AS [Milestone - Category], Milestone.[Critical Path] AS [Delivery Critical Path]
FROM
((Milestone
INNER JOIN Key_Match ON Milestone.ProjReturnID = Key_Match.ProjDetID)
INNER JOIN [vwProject - Last QTR] ON Key_Match.ProjID = [vwProject - Last QTR].ProjectID)
LEFT JOIN vwMilestoneTypeNewOld ON Milestone.MilestoneTypeID = vwMilestoneTypeNewOld.MilestoneTypeID;