title: SQL Server Time Series - a basic transformation
body: <p>I'm using SQL Server 2008</p>
  
  <p>I have a table <code>MainTable</code> with 3 columns <code>Date</code>, <code>Parameter</code>, <code>Value</code>. </p>
  
  <p>Sample data:</p>
  
  <pre><code>Date           Parameter      Value
  -------------+--------------+-------
  01-Jan-2010  | Temperature  | 30
  01-Jan-2010  | SnowLevel    |  2
  01-Jan-2010  | Humidity     | 60
  02-Jan-2010  | Temperature  | 32
  02-Jan-2010  | SnowLevel    |  5
  </code></pre>
  
  <p>Now I want to write a query to transform this time series data into the following table having a separate column for each parameter: </p>
  
  <pre><code>Date, Temperature, SnowLevel, Humidity 
  </code></pre>
  
  <p>with the following data:</p>
  
  <pre><code>Date          Temperature      SnowLevel     Humidity 
  ------------+----------------+-------------+----------
  01-Jan-2010 |     30         |      2      |    60
  02-Jan-2010 |     32         |      5      |    NULL
  </code></pre>
  
  <p>I know that SQL Server has a lot of functionality for working with time series, but I couldn't find any basic functionality that would make this transformation. I found tens of articles about data prediction with DMX, but no one about this basic stuff. </p>
  
  <p>A direct approach would be to join this table with itself for every parameter(/column), but I have hundreds of different parameters and definitely this approach wouldn't work in my case.</p>
  
  <p>Any help is very much appreciated!</p>