I have a table (actually a view, but simplified my example to a table) which gives me some data like this
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
I am looking to convert it to get a result like this
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
I have looked into pivot but looks like the record(row values) cannot be dynamic (i.e can only be certain predefined values).
Also, if there are more than 6 websites, I want to limit it to the first 6
Dynamic pivot makes sense, but I would have to incorporate it into my view ?? Is there a simpler solution for this ?
Here are the SQL scripts
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')
Edit: I am removing the ID as it was created for simplification. I think I should not have it.Sorry about it