Можно сохранить динамический характер ответа Мазьяра Тахери и избавиться от нулей:
if object_id('tempdb..#t') is not null
drop table #t
create table #t (fruit varchar(10), colour varchar(10))
insert #t
select 'Apple', 'Red' union all
select 'Apple', 'Green' union all
select 'Apple', 'Yellow' union all
select 'Apple', 'Yellow' union all
select 'Orange', 'Red' union all
select 'Orange', 'Yellow' union all
select 'Berry', 'Green' union all
select 'Berry', 'Red' union all
select 'Berry', 'Black' union all
select 'PineApple', 'Green'
declare @sql nvarchar(max), @colours nvarchar(max)
select @sql = '', @colours = ''
select @colours = @colours +'['+Colour +'],',
@sql = @sql +'isnull(['+Colour+'],0) '+Colour+','
from
(select distinct colour from #t) t2
set @colours = substring(@colours,1,len(@colours) - 1)
set @sql = substring(@sql,1,len(@sql) - 1)
select @sql = '
select Fruit,'+@sql +' from
(
select Fruit, Colour, 1 as CheckMark from #t
) as t2
pivot
(
SUM(CheckMark)
for Colour in ('+@colours+')
) as pivotTable'
execute (@sql)