Careful with table name alias

  • joeroshan

    SSChampion

    Points: 10377

    Comments posted to this topic are about the item Careful with table name alias

    ----------------------------------------------------------------------------------------------------------------------------------------------------
    Roshan Joe

    Jeff Moden -Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • Atif-ullah Sheikh

    SSChampion

    Points: 12495

    Very interesting...

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

  • SQLRNNR

    SSC Guru

    Points: 281243

    I think the results on this should be expected. I think the query was written interestingly enough.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • erajendar

    SSC Eights!

    Points: 840

    It is very interesting. However, am still not clear on [flag ='y' ]. Can someone tell me what is this flag. I didnt get any content in BOL.

    thanks


    erajendar

  • Koen Verbeeck

    SSC Guru

    Points: 258965

    Good question, although not that hard (for 2 points).

    erajendar (5/13/2010)


    It is very interesting. However, am still not clear on [flag ='y' ]. Can someone tell me what is this flag. I didnt get any content in BOL.

    The flag isn't actually there. Since it is contained in brackets, it is just an alias name for the table.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • muhammad.mazhar

    SSC Veteran

    Points: 290

    very interesting, this table alias in select clause got me puzzled for a moment. 🙂

  • Th. Fuchs

    SSC Enthusiast

    Points: 141

    fine, but correct is 'Careful with '

    (no rtrim and lower used)

  • keyur.patel

    SSC Enthusiast

    Points: 189

    Really good question, create confusion in mind for the "=" sign used in alias.

  • Kratos

    SSC Enthusiast

    Points: 128

    I learnt another thing, thanks to the Question of the day. 🙂

  • saranya.megalai

    SSC Rookie

    Points: 30

    if flag is alias then can we use next statement like

    select [flag='y'].some_data from [where]?

  • Koen Verbeeck

    SSC Guru

    Points: 258965

    saranya.megalai (5/14/2010)


    if flag is alias then can we use next statement like

    select [flag='y'].some_data from [where]?

    No 🙂

    I haven't tested it, but the following should work:

    select [flag='y'].some_data from [where] [flag='y']

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Kari Suresh

    Hall of Fame

    Points: 3712

    Really interesting and good question. :Wow:

    KSB
    -----------------------------
    Thousands of candles can be lit from a single candle, and the life of the candle will not be shortened. Knowledge and happiness never decreases by being shared.” - Buddha

  • malleswarareddy_m

    SSCertifiable

    Points: 5847

    Really its a good question about square brackets.we can use square brackets efficiently at any time.

    Malleswarareddy
    I.T.Analyst
    MCITP(70-451)

  • RichardDouglas

    SSCarpal Tunnel

    Points: 4029

    Interesting question, it was the alias that almost caught me out. Have seen plenty of attributes named as reserved words in the past which has caused a few issues unless squared brackets were used. Thinking back I had an interview question once where there was a table called ORDER and the question was what would happen.

    Hope this helps,
    Rich

    [p]
    [/p]

  • DaveD-128295

    Mr or Mrs. 500

    Points: 578

    saranya.megalai (5/14/2010)


    if flag is alias then can we use next statement like

    select [flag='y'].some_data from [where]?

    Yes it would look like:

    Select [flag ='y' ].some_data from [where] [flag ='y' ]

Viewing 15 posts - 1 through 15 (of 45 total)

You must be logged in to reply to this topic. Login to reply