I would like to know if I have this SQL logic decoded correctly. Here is the the SQL:
,[hrs].[Hours] - SUM(CASE WHEN [UnitState].[UnitStateType] <> 'ACTIVE' THEN [Allocation].[AllocatedEnergyMwh] ELSE 0 END / CAST([Unit].[NetDependableCapacity] AS FLOAT)) AS SH
I interpret this as saying:
if [UnitState].[UnitStateType] does not equal active then SH equals the sum of [Allocation].[AllocatedEnergyMwh] /
(float)[Unit].[NetDependableCapacity].
else SH = [hrs].[Hours]
Not exactly.
There is no else for SH. The else only affects the sum aggregate. More accurately, it says:
The else is only used to ignore the active AllocatedEnergyMwh in the sum. It does this by setting AllocatedEnergyMwh = 0 in those cases.