<small><pre>
BEGIN
-- ----------------------------------------------------
-- Update from tables with ProductoID=ElementoID
-- ----------------------------------------------------
UPDATE
    composicion AS T2,
    vidquoten3 AS T1,
    precios AS T3,
    productos AS T4
SET 
    T1.VidQuotePrecio = CalculoPrecio(
                        @Ancho, 
                        @Alto,
                        (CASE (@Lista)
                          WHEN 0 THEN T3.PrecioProd00
                          WHEN 1 THEN T3.PrecioProd01
                          WHEN 2 THEN T3.PrecioProd02
                          WHEN 3 THEN T3.PrecioProd03
                        END),
                        T4.Magnitud,
                        T2.OffsetVanoAlto,
                        T2.OffsetVanoAncho,
                        T2.CoefVanoAlto,
                        T2.CoefVanoAncho,
                        T2.ValorElemento) * @Coeficiente,
    T1.VidQuotePrecioP= CalculoPrecio(
                        @Ancho, 
                        @Alto,
                        (CASE (@Lista)
                          WHEN 0 THEN T3.PrecioProd00
                          WHEN 1 THEN T3.PrecioProd01
                          WHEN 2 THEN T3.PrecioProd02
                          WHEN 3 THEN T3.PrecioProd03
                        END),
                        T4.Magnitud,
                        T2.OffsetVanoAlto,
                        T2.OffsetVanoAncho,
                        T2.CoefVanoAlto,
                        T2.CoefVanoAncho,
                        T2.ValorElemento) * @Coeficiente * @Cantidad 
WHERE
    T1.VidQuoteID = @Presupuesto AND
    T1.VidQuoteItem = @PresupuestoItem AND
    T1.VidQuoteProdID = T1.VidQuoteElementoID AND 
    T2.ProductoID = T1.VidQuoteProdID AND 
    T2.ElementoID = T1.VidQuoteElementoID AND 
    T2.ComposicID = T1.VidQuoteComposicID AND 
    T3.ProductoID = T2.ElementoID AND 
    T4.ProductoID = T3.ProductoID;
-- ----------------------------------------------------
-- Update from tables with ProductoID<>ElementoID
-- ----------------------------------------------------
UPDATE
    vidquoten3 AS W1,
    (SELECT 
        V1.VidQuoteProdID,
        V1.VidQuoteElementoID,
        V1.VidQuoteComposicID,
        SUM(CalculoPrecio(
            @Ancho, 
            @Alto,
            (CASE (@Lista)
              WHEN 0 THEN V4.PrecioProd00
              WHEN 1 THEN V4.PrecioProd01
              WHEN 2 THEN V4.PrecioProd02
              WHEN 3 THEN V4.PrecioProd03
            END),
            V5.Magnitud,
            V2.OffsetVanoAlto + V3.OffsetVanoAlto,
            V2.OffsetVanoAncho + V3.OffsetVanoAncho,
            V2.CoefVanoAlto * V3.CoefVanoAlto,
            V2.CoefVanoAncho * V3.CoefVanoAncho,
            V2.ValorElemento * V3.ValorElemento)) * @Coeficiente AS VidQuotePrecio,
        SUM(CalculoPrecio(
            @Ancho, 
            @Alto,
            (CASE (@Lista)
              WHEN 0 THEN V4.PrecioProd00
              WHEN 1 THEN V4.PrecioProd01
              WHEN 2 THEN V4.PrecioProd02
              WHEN 3 THEN V4.PrecioProd03
            END),
            V5.Magnitud,
            V2.OffsetVanoAlto + V3.OffsetVanoAlto,
            V2.OffsetVanoAncho + V3.OffsetVanoAncho,
            V2.CoefVanoAlto * V3.CoefVanoAlto,
            V2.CoefVanoAncho * V3.CoefVanoAncho,
            V2.ValorElemento * V3.ValorElemento)) * @Coeficiente * @Cantidad AS VidQuotePrecioP
    FROM
        fzggestion.composicion AS V3,
        fzggestion.composicion AS V2,
        fzggestion.vidquoten3 AS V1,
        fzggestion.precios AS V4,
        fzggestion.productos AS V5
    WHERE
        V1.VidQuoteID = @Presupuesto AND
        V1.VidQuoteItem = @PresupuestoItem AND
        V3.ProductoID = V2.ElementoID AND 
        V2.ProductoID = V1.VidQuoteProdID AND 
        V2.ElementoID = V1.VidQuoteElementoID AND 
        V2.ComposicID = V1.VidQuoteComposicID AND 
        V4.ProductoID = V3.ElementoID AND 
        V5.ProductoID = V4.ProductoID AND 
        V1.VidQuoteProdID <> V1.VidQuoteElementoID AND 
        V3.ElementoPM = 0
    GROUP BY V1.VidQuoteElementoID , V1.VidQuoteComposicID) AS W2
SET
    W1.VidQuotePrecio = W2.VidQuotePrecio,
    W1.VidQuotePrecioP = W2.VidQuotePrecioP
WHERE
    W2.VidQuoteProdID = W1.VidQuoteProdID AND 
    W2.VidQuoteElementoID = W1.VidQuoteElementoID AND 
    W2.VidQuoteComposicID = W1.VidQuoteComposicID AND 
    W1.VidQuoteID = @Presupuesto AND
    W1.VidQuoteItem = @PresupuestoItem AND
    W1.VidQuoteProdID <> W1.VidQuoteElementoID;
END
</pre></small>