April 14, 2012 at 4:45 pm
I have a working pivot query. I want to add two more columns to it, that also must be pivoted. I am struggling to get it to work.
--I need to add these two columns:
, COUNT(CASE WHEN Outcome IN ('Passed', 'Failed', 'Blocked') THEN outcome END) AS TotalExecuted
,COUNT(outcome) AS TotalPlanned
--to this existing query (which works)
select *
from
(Select Distinct outcome,DTS.SuitePath,FTR2.TestCaseId
from dbo.FactTestResult FTR
Join DimTestResult TR on FTR.ResultSK = TR.ResultSK
Join CurrentWorkItemView WI
On FTR.TestCaseId = WI.System_Id
Join DimTestSuite DTS on FTR.TestSuiteSK = DTS.TestSuiteSK
inner Join(select TestSuiteSK,TestCaseId, Max(resultdate) as Max_ResultDate from dbo.FactTestResult
group by TestSuiteSK,testcaseid) FTR2
on FTR.TestCaseId = ftr2.TestCaseId
and FTR.ResultDate = FTR2.Max_ResultDate
where WI.Microsoft_VSTS_Common_Priority in (1,2,3,4,5)
and DTS.suitepath like '\17.2 - FY00 FQR Top Secret%'
)p
pivot(count([outcome]) for [outcome] in ([Blocked],[Failed],[Never Run],[Passed])) as pvt
When I remove the pivot operator from the above query and add the additional two lines after the first line of the query select statement returns results.
--this runs
Select Distinct outcome,DTS.SuitePath,FTR2.TestCaseId
, COUNT(CASE WHEN Outcome IN ('Passed', 'Failed', 'Blocked') THEN outcome END) AS TotalExecuted
,COUNT(outcome) AS TotalPlanned
from dbo.FactTestResult FTR
Join DimTestResult TR on FTR.ResultSK = TR.ResultSK
Join CurrentWorkItemView WI
On FTR.TestCaseId = WI.System_Id
Join DimTestSuite DTS on FTR.TestSuiteSK = DTS.TestSuiteSK
inner Join(select TestSuiteSK,TestCaseId, Max(resultdate) as Max_ResultDate from dbo.FactTestResult
group by testcaseid, TestSuiteSK) FTR2
on FTR.TestCaseId = ftr2.TestCaseId
and FTR.ResultDate = FTR2.Max_ResultDate
where WI.Microsoft_VSTS_Common_Priority in (1,2,3,4,5)
and DTS.suitepath like '\17.2 - FY00 FQR Top Secret%'
group by ftr2.testcaseid, dts.suitepath, outcome
However, I need this information to pivot.
Please will someone show me which lines to modify in my pivot statement so that it works with the additional two columns TotalExecuted and TotalPlanned?
-
April 16, 2012 at 4:08 am
April 16, 2012 at 5:39 am
This might help:
April 16, 2012 at 6:31 pm
Thank you very much for the links.
April 16, 2012 at 9:50 pm
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply