0

これは私のSQL文です。機能していません。

UPDATE dbo.Smoothie
SET TotalCalories = (SELECT 
                        SUM(CASE WHEN (Unit = 2) THEN f.Energ_Kcal * f.GmWt_2 * si.Quantity / 100 
                                 ELSE f.Energ_Kcal * f.GmWt_1 * si.Quantity / 100 
                            END) AS calories
                     FROM dbo.SmoothieIngredients AS si
                     INNER JOIN dbo.FoodAbbrev AS f ON si.FoodId = f.Id
                     WHERE si.SmoothieId = SmoothieId  ---> i want to pass the SmoothieId from the main update statement to the subquery.
                    )

S2 という名前を付けようとしましたが、まだ機能していません。

UPDATE dbo.Smoothie as S2
SET S2.TotalCalories = (SELECT 
                           SUM(CASE WHEN (Unit = 2) THEN f.Energ_Kcal * f.GmWt_2 * si.Quantity / 100 
                                    ELSE f.Energ_Kcal * f.GmWt_1 * si.Quantity / 100 
                                END) AS calories
                        FROM dbo.SmoothieIngredients AS si
                        INNER JOIN dbo.FoodAbbrev AS f ON si.FoodId = f.Id
                        WHERE si.SmoothieId = S2.SmoothieId)
4

1 に答える 1