Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    1

    Unanswered: 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'

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    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 ...
    )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •