UPDATE main
SET main.PCH_2YR =
(SELECT TOP 1 sub.PCH_2YR FROM [dbGlobalPricingMatrix].[dbo].[tblPCHLookup_Test] sub WHERE
sub.capid = main.capid AND
sub.milespa = main.mileage AND
sub.maintained = main.maintenance AND sub.pch_2yr IS NOT NULL)
FROM [dbWebsiteLO3-PRICING]..Vehicles_Staging_Data main
I only want to set the value if the subquery returns a value that isn't NULL. How can I do that?
Only one row will ever match the conditions, but I only want to use it's value if it's not NULL.
WHEREof the subquery is essentially aJOIN- 3 of the 4 conditions simply joinmainandsub. BTWTOP 1without an ORDER BY actually meanspick one row at random. Is that what you want?