SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: AS recognition

  1. #1
    SitePoint Addict streetlife's Avatar
    Join Date
    Mar 2004
    Location
    D-Town
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AS recognition

    This is actually for a hugely more complex query, but on the most basic level, why does:
    SELECT 1 AS a,2 AS b,a+b as c
    give an error as columns 'a' and 'b' not recognized?

    I mean if 'a' and 'b' are both complex equations then surely it makes no sense to have them calculated again to create 'c'? Is there a way?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    nope, you gots to repeat them, you cannot use an alias in a subsequent expression

    SELECT 1 AS a, 2 AS b, 1+2 as c
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict streetlife's Avatar
    Join Date
    Mar 2004
    Location
    D-Town
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok thanks.


Bookmarks

Posting Permissions

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