/****** Script for SelectTopNRows command from SSMS ******/
declare @ActivityYear int = 2014
declare @ActivityYear1 int = 2015
declare @ActivityMonth int = 1
declare @ActivityMonth1 int = 3
Select FinancialCategory, ID, (CONVERT(varchar(5), ActivityMonth) + '-'
+ CONVERT(varchar(5), ActivityYear)) As [Month-Year], Sum(HoursCharged) As [Hours]
FROM Forecast
where (ActivityMonth between @ActivityMonth and @ActivityMonth1)
AND (ActivityYear between @ActivityYear and @ActivityYear1)
AND FinancialCategory = 'Forecast'
Group By FinancialCategory, ID,ActivityMonth, ActivityYear
This Outputs a table that looks like this:
And I would like to transpose it to have the hours for each ID broken out by the dates in the range. Note: this range of dates will be dynamic, I set initial dates for testing purposes.