If I run this code, I get the proper results:
Results: 3 4 1
If I run this one, I get the proper results:
Results: 2 1 0
But if I combine them, I get weird results:
Results: 9 12 3 16 8 0
It looks like the first three are multiplied by three, and the next three are multiplied by 8.
Any ideas?
Thanks,
James
Code:
SELECT
SUM(CASE WHEN MS.strMilestoneStatus = 'GREEN' THEN 1 ELSE 0 END) [COUNT_GREEN],
SUM(CASE WHEN MS.strMilestoneStatus = 'YELLOW' THEN 1 ELSE 0 END) [COUNT_YELLOW],
SUM(CASE WHEN MS.strMilestoneStatus = 'RED' THEN 1 ELSE 0 END) [COUNT_RED]
FROM tblProject AS P
--JOIN for milestone statuses
LEFT JOIN tblProjectMilestone as MS
ON P.intProjectID = MS.int_fk_ProjectID
WHERE
(11 IS NULL OR P.intProjectID = 11)
Results: 3 4 1
If I run this one, I get the proper results:
Code:
SELECT
SUM(CASE WHEN PB.strBudgetStatus = 'GREEN' THEN 1 ELSE 0 END) [COUNT_BUDGET_GREEN],
SUM(CASE WHEN PB.strBudgetStatus = 'YELLOW' THEN 1 ELSE 0 END) [COUNT_BUDGET_YELLOW],
SUM(CASE WHEN PB.strBudgetStatus = 'RED' THEN 1 ELSE 0 END) [COUNT_BUDGET_RED]
FROM tblProject AS P
--JOIN for budget statuses
LEFT JOIN tblProjectBudget as PB
ON P.intProjectID = PB.int_fk_ProjectID
WHERE
(11 IS NULL OR P.intProjectID = 11)
Results: 2 1 0
But if I combine them, I get weird results:
Code:
SELECT
SUM(CASE WHEN MS.strMilestoneStatus = 'GREEN' THEN 1 ELSE 0 END) [COUNT_GREEN],
SUM(CASE WHEN MS.strMilestoneStatus = 'YELLOW' THEN 1 ELSE 0 END) [COUNT_YELLOW],
SUM(CASE WHEN MS.strMilestoneStatus = 'RED' THEN 1 ELSE 0 END) [COUNT_RED],
SUM(CASE WHEN PB.strBudgetStatus = 'GREEN' THEN 1 ELSE 0 END) [COUNT_BUDGET_GREEN],
SUM(CASE WHEN PB.strBudgetStatus = 'YELLOW' THEN 1 ELSE 0 END) [COUNT_BUDGET_YELLOW],
SUM(CASE WHEN PB.strBudgetStatus = 'RED' THEN 1 ELSE 0 END) [COUNT_BUDGET_RED]
FROM tblProject AS P
--JOIN for milestone statuses
LEFT JOIN tblProjectMilestone as MS
ON P.intProjectID = MS.int_fk_ProjectID
--JOIN for budget statuses
LEFT JOIN tblProjectBudget as PB
ON P.intProjectID = PB.int_fk_ProjectID
WHERE
(11 IS NULL OR P.intProjectID = 11)
Results: 9 12 3 16 8 0
It looks like the first three are multiplied by three, and the next three are multiplied by 8.
Any ideas?
Thanks,
James