Unary & Aliases

  • I think I may need eye glasses, I really had to look hard at the commas to differentiate them from periods... I almost chose the Incorrect Syntax error.

  • My first opinion was: very exotic question far away from practical usage.

    But later I changed my minds. Never thought about arithmetical operations in T-SQl work in such way. Thanks a lot.

  • Nice question.

    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

  • It's a nice and interesting question. Thanks.

  • Ah yes, my "favorite" bit of SQL syntax

    select 0 [A]

    A fun bug to find when I accidentally delete a comma and then try to figure out what's wrong with the output of

    select col1

    col2,

    col1003

    from sometable

    What? I can't be the only one!:ermm:

    Thanks for the question!

  • Amusing and fairly easy question.

    The misprints in the explanation may have left some people confused. All three alias forms are wrong (1st missing "= <", second and third bpth missing "alias").

    edit: I can make typos too. Fixed.

    Tom

  • Good puzzler - thanks. Nice coverage of different scenarios.

  • Tom.Thomson (9/13/2011)


    Amusing and fairly easy question.

    The misprints in the explanation may have left some people confused. All three alias forms are wrong (1st missing "= <", second and third bpth missing "alias").

    edit: I can make typos too. Fixed.

    Unfortunately, the editor to contribute with a question, sometime, changes the text both in the question and more often in the explanation. The explanation was victim of this change. I think because of GREAT and LESS sign that are misinterpreted as html syntax.

  • Olga B (9/13/2011)


    Ah yes, my "favorite" bit of SQL syntax

    select 0 [A]

    A fun bug to find when I accidentally delete a comma and then try to figure out what's wrong with the output of

    select col1

    col2,

    col1003

    from sometable

    What? I can't be the only one!:ermm:

    Thanks for the question!

    My favorite syntax is

    select col1 AS [newcolname/sometime user friendly col name]

    from sometable

    Other syntax is less readable and as you wrote it may lead to unwanted bug. But maybe very usefull for code generators.

  • Carlo - absolutely that is confusing. When I intend to alias the column, I prefer to use [ColumnName] = col1 syntax, which aligns all my column names nicely.

    The problem arises when I lose the comma by accident, and SQL turns col2 into an alias for col1, thus messing up my output.

  • Interesting question and took quite sometime to figure out and also learnt along the way.

    Thank you.

Viewing 11 posts - 16 through 25 (of 25 total)

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