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.

    Requires Free Membership to View

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

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: