Here is my SQL:
SELECT fho$-wxbo$ as amt FROM wip220, frp001 WHERE wxot=fhot and wxpro=fhpro and wxrdat between 1050401 and 1050404 and amt > 0
I get the error: "Column AMT not in specified tables" and I don't know how to fix it.
You cannot use a column alias in the WHERE clause. Change your query to:
select fho$-wxbo$ as amt from wip220, frp001 where wxot=fhot and wxpro=fhpro and wxrdat between 1050401 and 1050404 and fho$-wxbo$ > 0
The reason for this restriction on the alias comes from the way in which queries are executed. The first step in execution is the FROM clause, as modified by the WHERE clause. Next, the GROUP BY clause is executed, followed by the HAVING clause. Then, the SELECT list is evaluated, and finally, the ORDER BY clause. So you see, at the time the WHERE clause is evaluated, the database optimizer doesn't recognize the alias name. Note that you can use the alias in the ORDER BY.
This was first published in April 2005