SSIS Package Execution History

Pivot SSIS execution history durations

use SSISDB
go
set nocount on;
DECLARE @columns NVARCHAR(MAX), @sql NVARCHAR(MAX);
SET @columns = N'';
SELECT @columns += N', p.' + QUOTENAME(StartDate)
FROM (select distinct cast(start_time as date) as StartDate from catalog.executions) AS x;

SET @sql = N'SELECT FolderName, PackageName, ' + STUFF(@columns, 1, 2, '') + '
FROM
(
    select
    package_name as PackageName,
    ce.folder_name as FolderName,
    cast(start_time as date) as StartDate, 
    datediff(s,start_time,end_time) as DurationSec
   FROM catalog.executions as ce
) AS j
PIVOT
(
  SUM(DurationSec) FOR StartDate IN ('
  + STUFF(REPLACE(@columns, ', p.[', ',['), 1, 1, '')
  + ')
) AS p;';
PRINT @sql;
EXEC sp_executesql @sql;