• It seems like you're wanting to copy the non-NULL values for any given SKU into the NULL values, correct? If so, this should do it:

    ;WITH NullFill(SKU,FillPrice,FillCost,FillSalePrice) AS(

    SELECT VendorSKU,MAX(Price)AS Price, MAX(Cost) AS Cost, MAX(SalePrice) AS SalePrice

    FROM @DiamondsMissingData

    GROUP BY VendorSKU

    )

    UPDATE @DiamondsMissingData

    SET Price = CASE WHEN Price IS NULL THEN FillPrice ELSE Price END,

    Cost = CASE WHEN Cost IS NULL THEN FillCost ELSE Cost END,

    SalePrice = CASE WHEN SalePrice IS NULL THEN FillSalePrice ELSE SalePrice END

    FROM @DiamondsMissingData A

    INNER JOIN NullFill B

    ON A.VendorSKU = B.SKU

    That should take the non-NULL value for each of the three potentially-NULL columns, and fill it in where the value is NULL, ignoring it if it's not NULL.

    However, this won't work if the same SKU can have multiple values for any of the three nullable columns; if there's a variation in price, for example, this will make all price values the same. In your provided data, this isn't a problem, but if it could happen in your real data, this will be problematic.

    If that's the case, a better solution can certainly be worked out; please provide an example of a case where that might happen, and adjustments will be made! 🙂

    - 😀