We value your feedback.
Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!
SELECT v.rep, Sum(v.[Gross Rev]) as GrossRev, DATENAME(month, v.Funded) as Mth , month(v.Funded) as MthI Into #temp 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())-@) Group by rep, v.Funded ORDER BY v.rep, month(v.Funded) --Create Dynamic SQl and Pivot declare @sql varchar(4000) declare @columns varchar(8000) select @columns = coalesce(@columns+',','') + '[' + Mth + ']' from #temp group by Mth, MthI order by MthI set @sql = ' SELECT [rep], ' + @columns + ' FROM (SELECT [rep], [GrossRev], [Mth] as Mth from #temp) src PIVOT (Sum ([GrossRev]) FOR Mth IN (' + @columns + ') ) AS pvt' EXEC (@sql) Drop table #temp
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
|Read top line from CSV file||14||60|
|I have an unknown large SQL database I want to get rid of||10||47|
|How to create and use encrypted columns in SQL 2005?||15||64|
|SSIS Error on Bat File execute||2||15|
Join the community of 500,000 technology professionals and ask your questions.