create table #temp
(
PositionCode varchar(10),
FormatCode varchar(10),
PubDate date ,
Cliente varchar(10),
Sold int ,
Active int
)
go
insert into #temp select 'PP','FINDX ','2020-05-28','BARILLA ',1,1
insert into #temp select 'PP','FINSX ','2020-05-28','Client1 ',1,0
insert into #temp select 'PP' ,'MTDX ','2020-05-28','Blu ',0,1
insert into #temp select 'PP' ,'MTSX ','2020-05-28','Fiat ',0,1
insert into #temp select 'ATT','3X2_EXT ','2020-05-28','Vast ',0,1
insert into #temp select 'UP' ,'MD6X28 ','2020-05-28','Fiat ',1,0
insert into #temp select 'PP' ,'FINDX ','2020-05-29','RCS ',1,0
insert into #temp select 'PP' ,'FINSX ','2020-05-29','RCS ',0,1
insert into #temp select 'PP' ,'MTDX ','2020-05-29','Bull ',0,1
insert into #temp select 'PP' ,'MTSX ','2020-05-29','Vast ',0,1
insert into #temp select 'ATT','3X2_EXT ','2020-05-29','Blue ',0,1
insert into #temp select 'UP' ,'MD6X28 ','2020-05-29','Vast ',0,1
go
select 'SQL Output',
PositionCode
, FormatCode
, max(case when PubDate = '2020-05-28' then Cliente end) as '2020-05-28'
, max(case when PubDate = '2020-05-29' then Cliente end) as '2020-05-29'
from #temp
group by PositionCode,FormatCode
go