How to execute a query based on the condition if a column exists?
Since you aren't using column y, you can ignore it in your first query. Then, you can simplify this with a single statement:

SELECT 
    x, 
    A = z
FROM table1
WHERE y!=0 and z is not null