Can't use coalesce in SQL on grid?

Why can’t I use this:

SELECT
    coalesce (w.WarehouseCode,Mast.WarehouseCode) as WarehouseCode,
    coalesce (w.QuantityOnHand,Mast.QuantityOnHand) as QuantityOnHand,
    coalesce (w.QuantityOnSalesOrder,Mast.QuantityOnSalesOrder) as QuantityOnSalesOrder,
    coalesce (w.QuantityOnPurchaseOrder,Mast.QuantityOnPurchaseOrder) as QuantityOnPurchaseOrder,
    coalesce (w.QuantityOnBackOrder,Mast.QuantityOnBackOrder) as QuantityOnBackOrder
FROM
    IM_ItemWarehouse_Master Mast
left join
     IM_ItemWarehouse w on
w.WarehouseCode = Mast.WarehouseCode
AND w.Itemcode = '[ATRNUM]' 

In the SQL Select Statement of a grid?

I get this error:

Error while accessing the database:
Column 'WarehouseCode' in field list is ambiguous
SELECT WarehouseCode, QuantityOnHand, QuantityOnSalesOrder, QuantityOnPurchaseOrder, QuantityOnBackOrder from IM_ItemWarehouse_Master Mast left join IM_ItemWarehouse w on w.WarehouseCode = Mast.WarehouseCode AND w.Itemcode = '10039atr'

Which shows a different Sql statement. Stripped of my coalesce.

Wait… its working now… apparently when I modified the Sql to my new statement Scriptcase Dropped the fields from the displayed fields.
Once I added them back, then it works now.

Maybe this will help someone else.
Thanks!