Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 GROUP BY MONTHS_new

Author  Topic 

lwarunek
Starting Member

22 Posts

Posted - 2008-04-07 : 11:24:05
Hi Everybody.

I know there has been a lot stuff in the past about this subject but I think my case could still be a bit different.
There is the SQL:

SELECT
SUM(
CASE WHEN Datepart(month,P.DateClosed) = M.month_value THEN
P.ActualValue/3
ELSE
0
END
)as rev,
M.month_value,
--M.month_name
Datepart(year,P.DateClosed)

FROM
Months M
LEFT OUTER JOIN Projects P ON
M.month_value = Datepart(month,P.DateClosed)
LEFT OUTER JOIN ClosureProbability CP ON
CP.ClosureProbID = P.ClosureProbabilityID

WHERE
P.EndDate>getDate() and P.Dropped<>1 and CP.Closure_Probability_Percent =100

GROUP BY
M.month_value,
--M.month_name,
Datepart(year,P.DateClosed)

ORDER BY
M.month_value,
Datepart(year,P.DateClosed)desc



The results looks like:

133 1 2008
46 2 2008
333 3 2008
500 7 2007
125 11 2007

I want to see the months that don't have any values too.
For some reason I can only see the ones that are in the records, even though I have joined them to my months table.

Can u help me?

Cheers

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-04-07 : 12:13:21
Can enddate be null? If so, this part of your query
WHERE
P.EndDate>getDate()
will not be true when endDate is null. Same is true for DateClosed.


Jim
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-08 : 00:55:31
Cross post
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=100440



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -