Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL - How to use a field from AS in Criteria

Status
Not open for further replies.

LinuxKommy

Technical User
Apr 2, 2002
31
US
This may sound way simplistic, but this SQL statement won't work

SELECT *,CInt(Mid(Product,4,5)) AS Cap FROM LA WHERE Cap=30;

I have absolutely no idea what is wrong...can anyone help me?

thanks,
Douglas
 
You can't. The field cap does not exist until the query runs so it cannot be used as part of the selection criteria for the query.

The proper syntax would be.

SELECT *,CInt(Mid(Product,4,5)) AS Cap
FROM LA
WHERE CInt(Mid(Product,4,5)) =30

If you don't actually need to see 'cap' as part of the results of the query you can leave it out of the select clause altogether as in

SELECT *
FROM LA
WHERE CInt(Mid(Product,4,5)) =30
 
Code:
SELECT * from
(select la.*,CInt(Mid(Product,4,5)) AS Cap
FROM LA) dt
WHERE Cap =30
 
select *, 30 as Cap
from LA
where CInt(Mid(Product,4,5)) = 30

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top