SELECT F1, F2, F3, F4FROM Table1WHERE F1 = CASE WHEN P1 = 0 THEN F1 ELSE P1 END AND F2 = CASE WHEN P2 = 0 THEN F2 ELSE P2 END AND F3 = CASE WHEN P3 = 0 THEN F3 ELSE P3 END AND F4 = CASE WHEN P4 = 0 THEN F4 ELSE P4 END