Не проверено, но, возможно, это поможет
Declare @SQL varchar(max) = '
Select *
From (Select Distinct
Securitization
,ReportingDate
,RemittableCollections
From Securitization.dbo.SecuritizationReporting
) src
Pivot ( sum(RemittableCollections) for ReportingDate in ( ' + Stuff((Select Distinct
',' + QuoteName(ReportingDate)
From Securitization.dbo.SecuritizationReporting
Order By 1
For XML Path('')),1,1,'') +' ) ) pvt
'
--Print(@SQL)
Exec(@SQL)
РЕДАКТИРОВАТЬ - Удалить NULLS
Declare @NoNulls varchar(max) = Stuff( (
Select Distinct
',' + QuoteName(ReportingDate) +' = IsNull(' + QuoteName(ReportingDate) +',0)'
From Securitization.dbo.SecuritizationReporting
Order By 1
For XML Path('')),1,1,'')
Declare @SQL varchar(max) = '
Select [Securitization]
,' + @NoNulls + '
From (Select Distinct
Securitization
,ReportingDate
,RemittableCollections
From Securitization.dbo.SecuritizationReporting
) src
Pivot ( sum(RemittableCollections) for ReportingDate in ( ' + Stuff((Select Distinct
',' + QuoteName(ReportingDate)
From Securitization.dbo.SecuritizationReporting
Order By 1
For XML Path('')),1,1,'') +' ) ) pvt
'
--Print(@SQL)
Exec(@SQL)