You can dynamically generate columns.following is code
Create table logtable
(
batch varchar(5),
date1 DateTime,
Duration integer)
Insert into logtable values('B1','01-jAN-2017',80),
('B2','01-jAN-2017',40),
('B1','02-jAN-2017',20),
('B2','02-jAN-2017',50)
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT ',' + QUOTENAME(DATE1)
from logtable
group by date1
order by DATE1
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query = 'SELECT BATCH,' + @cols + ' from
(
select BATCH, DATE1, DURATION
from LOGTABLE
) x
pivot
(
sum(DURATION)
for DATE1 in (' + @cols + ')
) p '
execute(@query);