Summing up the value of related entries during an update

37 views Asked by At

I am attempting to change a value of a field for products on Volusion shopping engine. The field I want to set is 'HideProduct' to 'Y' if it's children products are equivalent to 0 (negative stocks also count as zero). However, some products don't have children, which are ignored.

I don't have direct access to the server or database, and this script is being passed though with the errors suppressed. The error I get is simply "An error has occurred. Please try your request again, or contact customer service for assistance. Thank you." They don't offer customer support for SQL.

This is the script I am trying to run:

UPDATE
    Products_Joined
SET
    HideProduct = 'Y'
WHERE
    -- Only apply to products where there are no in stock children
    0 = SUM(
            SELECT
                CASE 
                    WHEN Pb.DoNotAllowBackOrders = 'N' THEN 1
                    WHEN Pb.StockStatus < 0 THEN 0
                    ELSE Pb.StockStatus
                END
            FROM
                Products_Joined Pb
            WHERE 
                ProductCode = Pb.IsChildOfProductCode 
        )
        AND
    --Only apply to products with children
    0 < TOTAL(
            SELECT
                Pc.StockStatus
            FROM
                Products_Joined Pc
            WHERE 
                ProductCode = Pc.IsChildOfProductCode 
        )

I am attempting to pass the Product Code of the UPDATE part of the script into the SELECT parts of the code. I think that's where the issue might be.

0

There are 0 answers