I need to create an SQL table or view that would generate columns for every month between a range of two dates. So a range of 01/01/2014 - 04/01/2014 would generate four columns with headers Jan 2014, Feb 2014, March 2014, April 2014. I also need it to populate the fields with data that pertain to those months from the following table, while any field with no appropriate data would be filled in with null values:
------------------------------------------------------
| Project# | Months | MonthValues |
------------------------------------------------------
| 001 | Jan 2014 | 1 |
------------------------------------------------------
| 002 | Feb 2014 | 2 |
------------------------------------------------------
This should create the table:
---------------------------------------------------------------------------------------
| Project# | Jan 2014 | Feb 2014 | March 2014 | April 2014 |
---------------------------------------------------------------------------------------
| 001 | 1 | null | null | null |
---------------------------------------------------------------------------------------
| 001 | null | 2 | null | null |
---------------------------------------------------------------------------------------
Using SQL server 2008.
Been trying to get my head around this for sometime without any luck, any help would be much appreciated!