If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > column alias in select?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-22-03, 16:02
hperez hperez is offline
Registered User
 
Join Date: Sep 2003
Posts: 1
column alias in select?

I would like to use the value calculated in one column in another colum by using it's alias. However, when I try that, I get an 'Invalid Column Name' error.

for example,

SELECT
sum(Price) as 'Sum_Price',
('Sum_Price' / 3) as 'One_Third_Sum_Price'
Reply With Quote
  #2 (permalink)  
Old 09-22-03, 16:10
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: column alias in select?

The SELECT clause can only refer to columns from tables in the FROM clause, so that won't work. Of course, you can do this:

SELECT
sum(Price) as 'Sum_Price',
sum(Price) / 3 as 'One_Third_Sum_Price'

Or you can do this:

SELECT
Sum_Price
Sum_Price / 3 as One_Third_Sum_Price
FROM
( SELECT sum(Price) as 'Sum_Price'
FROM ...
)
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On