SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Unary & Aliases


Unary & Aliases

Author
Message
Tom Thomson
Tom Thomson
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14524 Visits: 12238
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

matt.bowler
matt.bowler
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1417 Visits: 611
Good puzzler - thanks. Nice coverage of different scenarios.
Carlo Romagnano
Carlo Romagnano
SSCertifiable
SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)

Group: General Forum Members
Points: 5049 Visits: 3327
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.

I run on tuttopodismo
Carlo Romagnano
Carlo Romagnano
SSCertifiable
SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)SSCertifiable (5K reputation)

Group: General Forum Members
Points: 5049 Visits: 3327
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.

I run on tuttopodismo
Olga B
Olga B
SSChasing Mays
SSChasing Mays (642 reputation)SSChasing Mays (642 reputation)SSChasing Mays (642 reputation)SSChasing Mays (642 reputation)SSChasing Mays (642 reputation)SSChasing Mays (642 reputation)SSChasing Mays (642 reputation)SSChasing Mays (642 reputation)

Group: General Forum Members
Points: 642 Visits: 455
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.
zymos
zymos
Mr or Mrs. 500
Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)Mr or Mrs. 500 (598 reputation)

Group: General Forum Members
Points: 598 Visits: 259
Interesting question and took quite sometime to figure out and also learnt along the way.

Thank you.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search