Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.
Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.
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
|SQL, add where clause||5||23|
|How would you modify the following SQL Server 2008 stored procedure to prevent it's execution if the value being inserted into the field "BRANCH" is a duplicate ? Branch is the Primary Key.||2||18|
|Code works but breaks when I add one section||4||20|
|MS SQL AND PASSING A TABLE NAME TO A SPROC||5||14|