title: Converting rows to Columns in SQL
body: <p>I have a table (actually a view, but simplified my example to a table) which gives me some data like this</p>
  
  <pre><code> CompanyName website
   Google         google.com
   Google         google.net
   Google         google.org
   Google         google.in
   Google         google.de
   Microsoft       Microsoft.com
   Microsoft       live.com
   Microsoft       bing.com
   Microsoft       hotmail.com
  </code></pre>
  
  <p>I am looking to convert it to get a result like this </p>
  
  <pre><code>CompanyName website1      website2   website3   website 4   website5  website6 
  ----------- ------------- ---------- ---------- ----------- --------- --------
  Google      google.com    google.net google.org google.in   google.de NULL
  Microsoft   Microsoft.com live.com   bing.com   hotmail.com NULL      NULL
  </code></pre>
  
  <p>I have looked into pivot but looks like the record(row values) cannot be dynamic (i.e can only be certain predefined values). </p>
  
  <p>Also, if there are more than 6 websites, I want to limit it to the first 6</p>
  
  <p>Dynamic pivot makes sense, but I would have to incorporate it into my view ?? Is there a simpler solution for this ?</p>
  
  <p>Here are the SQL scripts</p>
  
  <pre><code>CREATE TABLE [dbo].[Company](
  
   [CompanyName] [varchar](50) NULL,
   [website] [varchar](50) NULL
  ) ON [PRIMARY]
  GO
  
  insert into company values ('Google','google.com')
  insert into company values ('Google','google.net')
  insert into company values ('Google','google.org')
  insert into company values ('Google','google.in')
  insert into company values ('Google','google.de')
  insert into company values ('Microsoft','Microsoft.com')
  insert into company values ('Microsoft','live.com')
  insert into company values ('Microsoft','bing.com')
  insert into company values ('Microsoft','hotmail.com')
  </code></pre>
  
  <p>Edit: I am removing the ID as it was created for simplification. I think I should not have it.Sorry about it</p>