First, you don't need nested case
statements. This should produce the same logic:
(CASE WHEN Form_Ref = 1091
THEN (DATA_SCALE_1 + DATA_SCALE_2 + DATA_SCALE_3 + DATA_SCALE_4) / 4.0
WHEN DATA_SCALE_1 IS NOT NULL
THEN DATA_SCALE_1
ELSE OLD_FIELD_CUST_TBL.SELECT_TEXT
END) AS Satisfaction
Second, column aliases cannot be used at the same level they are defined. The behavior your are describing makes it sound like there is a column called Form_Ref
in the tables (in the from
clause) as well as Form_Ref
being the target of an alias.