title: SQL Server PIVOT on key-value table
body: <p>I have a table that has attributes based on a key-value. Example:</p>
  
  <pre><code>CREATE TABLE ObjectAttributes
  (
    int objectId, key nvarchar(64), value nvarchar(512)
  )
  </code></pre>
  
  <p>When I select from this I get:</p>
  
  <pre><code>objectId  key      value
  ----------------------------
  1         Key 1    Value 1
  1         Key 2    Value 2
  </code></pre>
  
  <p>I was wondering if I could use the PIVOT syntax to turn this into:</p>
  
  <pre><code>objectId  Key 1     Key 2
  ---------------------------
  1         Value 1   Value 2
  </code></pre>
  
  <p>I know all of my tables will have the same keys. (Unfortunately I cannot easily change the table structure. This is what is leading me to attempt using PIVOTS).</p>
  
  <p>The big issue here though is that pivots require an aggregation function to be used. Is there a way to avert this? Am I completely wrong attempting this? Or is there a better solution?</p>