Je voudrais savoir si j'ai cette logique SQL décodée correctement. Voici le SQL:
,[hrs].[Hours] - SUM(CASE WHEN [UnitState].[UnitStateType] <> 'ACTIVE' THEN [Allocation].[AllocatedEnergyMwh] ELSE 0 END / CAST([Unit].[NetDependableCapacity] AS FLOAT)) AS SH
J'interprète cela comme disant:
if [UnitState].[UnitStateType] does not equal active then SH equals the sum of [Allocation].[AllocatedEnergyMwh] / (float)[Unit].[NetDependableCapacity]. else SH = [hrs].[Hours]
Pas exactement.
Il n'y a pas d' autre chose pour SH. L'autre affecte seulement l'agrégat de sum. Plus précisément, il est dit:
SH = hours - (the sum of AllocatedEnergyMwh where StateType != ACTIVE) / NetDependableCapacity
L'autre est seulement utilisé pour ignorer l'AllocatedEnergyMwh actif dans la sum. Il le fait en définissant AllocatedEnergyMwh = 0 dans ces cas.
C'est proche mais vous avez manqué les [heures]. [Heures] – partie du cas pour le premier.
if [UnitState].[UnitStateType] does not equal active then SH equals [hrs].[Hours] minus the sum of [Allocation].[AllocatedEnergyMwh] / (float)[Unit].[NetDependableCapacity]. else SH = [hrs].[Hours] minus (0)/[Unit].[NetDependableCapacity]
si [UnitState]. [UnitStateType] n'est pas égal à l'actif alors
[heures]. [Heures] less la sum ([Allocation]. [AllocatedEnergyMwh] / [Unité]. [NetDependableCapacity])
autrement
[heures]. [Heures] less la sum (0 / [Unité]. [NetDependableCapacity]) -> signification [heures]. [Heures] – 0