PodrÃas intentar hacer algo como esto.
;With CTE_Source As (
Select Fl, Col
, Val = Case
When Val Is Null Then 0
Else Case
When IsNumeric(Val) = 1 Then Cast(Val As Money)
Else 0
End
End
From dbo.Test
)
Select
Sum(Case When t.[Coverage] IS Null Then 0 Else t.[Coverage] End) As [Coverage]
, Sum(Case When t.[Premium] IS Null Then 0 Else t.[Premium] End) As [Premium]
, Sum(Case When t.[CALC1] IS Null Then 0 Else t.[CALC1] End) As [CALC1]
, Sum(Case When t.[CALC1] IS Null Then 0 Else t.[CALC1] End) * 0.50 As [CALC2]
, (Sum(Case When t.[CALC1] IS Null Then 0 Else t.[CALC1] End) * 0.50) + 10 As [CALC3]
From(
SELECT [Coverage] AS [Coverage], [Premium] AS [Premium], [CALC1] AS [CALC1]
FROM ( SELECT Fl, Col, Val FROM CTE_Source ) As Data
PIVOT ( SUM(Val) FOR Col IN( [Coverage], [Premium], [CALC1] ) ) AS pvt
) As t
That doesn't actually work as the OP requested. The goal is to read the formulas from the given table and apply them... not hard-code them.