Question : Grouping by Month

I have a column in the select statement below that is in the table as datetime

My ststement below doesn't work...it allows 2 records for a rep is the have 2 records in the same month. I need everything summed up for each month.

example:
rep                GrossRev      Mth
dsilverman      24598.8400      June
dsilverman      49262.9300      June
dsilverman      14706.8200      June
dsilverman      25027.0900      July
dsilverman      82055.6900      July
1:
2:
3:
4:
5:
6:
7:
8:
SELECT 	v.rep,
		Sum(v.[Gross Rev]) as GrossRev, 
		DATENAME(month, v.Funded) as Mth
 FROM   CRMPROD_01.dbo.v_P_Reporting v
 WHERE  v.Funded is not null and v.Status <> 'Closed' and (YEAR(v.Funded) = YEAR(getdate()))
		and (MONTH(v.Funded) > MONTH(getdate())-3)
Group by rep, v.Funded
 ORDER BY v.rep, Month(v.Funded)

Answer : Grouping by Month


To fix the error regarding order by,

Change this line -> ORDER BY v.rep, Month(v.Funded)

to ORDER BY v.rep, DATENAME(month, v.Funded)
Random Solutions  
 
programming4us programming4us