Thank you for your help in advance. I am looking for a neat solution for the following update scenario:
- I have a table TableA with 5 columns (KeyCol, colA, ColB, ColC, ColD)
- I have another table Table2 with 2 columns (KeyCol, AvgCol)
I want to do something like this:
update AvgCol in table2, joining on KeyCol
from this logic:
- if colA and ColB both have Non NUll values, calculate avg of COlA and COlB and store in tempA, else choose coalesce (Cola / colb) in TempA, if both are nUll, NULL in TempA
if colC and ColD both have Non NUll values, calculate avg of COlC and COlD and store in tempB, else choose coalesce (ColC / colD) in TempB, if both are nUll, NULL in TempB
if TempA and TempB both have Non NUll values, calculate avg of TempA and TempB and store in Table2.AvgCol, else choose coalesce (TempA / TempB), if both are nUll, NULL