SQL Query Pivot column help SQL 2012 Need Guru
Posted on 2013-11-21
Okay hoping to find an example on how to accomplish this. So I have a table called YearlyAnalysis that has the following columns:
Sample there are other columns this is good enough. So what I need to do is take the current Year (getdate()) and go back 3 years. What I am trying to get is columns such as this let's say we are in 2013 right so this:
2010 2011 2012 2013
If the year does not exist I still want a column for it with all nulls. Can anyone provide me a sample way to do this? I am using SQL Server 2012.