Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2005

    Unanswered: using column alias in SELECT (was "Asking")


    I have a question.

    select name, count, 1 Aa c1, 2 as c2, c1+c2 As total
    from table1

    From this example, the program will give out error message,
    c1, and c2 are invalid columns.

    In MS Access, it works. But, SQL query Analayer doesn't work this statement.
    So, does query analayzer handle this case?


  2. #2
    Join Date
    Apr 2002
    Toronto, Canada

    SQL Server does not allow you to use a column alias in the SELECT

    Access allows it, but Access is an anomaly | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Nov 2003
    Provided Answers: 8
    Quote Originally Posted by r937
    but Access is an anomaly
    Having had to maintain some reports in Access I can wholeheartedly agree
    It's even worse when people without any knowledge of relational databases try to create queries in therer (but that is another story and doesn't belong here)

  4. #4
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    I don't think that query will run as posted. I think that the use of the reserved word COUNT as a column name will cause havok when SQL Server tries to figure out what you want it to do.

    Based on my interpretation of your interpretation of SQL Server's interpretation of what you typed (from your rendition of the error message that SQL Server gave), it appears that SQL Server is trying to do grouping for you.

    See one of the sticky mesages at the top of the forum for direction on how to get correct answers quickly. Brett wrote up a great short post on ths, and I stole his post wholesale in the FAQ (Frequnetly Asked Questions) thread.


Posting Permissions

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