>>
>>Did you try running
>>
>>
>>;with cte as (
>>SELECT sponsor, fundtype, amount
>>FROM TIP_ApprovedFunding f
>>INNER JOIN TIP_Projects p ON p.TipID = f.TipID
>>WHERE p.ApprovedStatus = 'Active'
>>)
>> SELECT * from cte
>> PIVOT
>> (
>> SUM(amount) FOR FundType IN ([HSIP], [PL], [SPR], [STP], [TAP])
>> )
>> AS PivotTableAlias
>>
>>
>>This should work.
>>
>>Also, it should be
>>execute (@SQL)
>>
>>Note the parenthesis.
>
>Would you also know how to sort the result by Sponsor? Seems like it doesn't like ORDER BY no matter where I put it.
It should be after AS PivotTableAlias ORDER BY Sponsor
If it's not broken, fix it until it is.
My Blog