0

I'm stumped why this is not returning the correct value. I have this query:

SELECT 
  ClosingMonth,
  CAST(SUM(EstSale10)as DECIMAL (10,2)) as 'EstSale10',
  CAST(SUM(EstSale25)as DECIMAL(10,2)) as 'EstSale25'
FROM(
  SELECT ClosingMonth,
    SUM(EstSaleLessWar) OVER (PARTITION BY ClosingMonth) AS 'EstSale10',
    0.00 AS 'EstSale25'
  FROM dbo.Contracting_SAF
    WHERE OwnerID = '65'
        AND Year = '2013'
        AND ClosingMonth = 'December'
        AND Status != '10'
        AND ConfLevel = 'Not Likely (10%)'
   UNION ALL
   SELECT ClosingMonth,
     0.00 AS 'EstSale10',
     SUM(EstSaleLessWar) OVER (PARTITION BY ClosingMonth) AS 'EstSale25'
   FROM dbo.Contracting_SAF
     WHERE OwnerID = '65'
        AND Year = '2013'
        AND ClosingMonth = 'December'
        AND Status != '10'
        AND ConfLevel = 'Low (25%)') T
GROUP BY T.ClosingMonth

And my result is the following:

December | 0.00 | 29106570.00

Problem is using a number_format in PHP shows this value is 29,106,570.00 when it should be only 2,910,657.00 as I get in this single query below:

SELECT SUM(EstSaleLessWar) 
FROM Contracting_SAF
WHERE OwnerID = '65' 
    AND Year = '2013' 
    AND ClosingMonth = 'December' 
   AND ConfLevel = 'Low (25%)'

result for query:

2910657.00

Help!! What am I doing wrong?

4

0 回答 0