Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Unary & Aliases


Unary & Aliases

Author
Message
TomThomson
TomThomson
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10704 Visits: 12002
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.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1345 Visits: 599
Good puzzler - thanks. Nice coverage of different scenarios.
Carlo Romagnano
Carlo Romagnano
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3602 Visits: 3235
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.
Carlo Romagnano
Carlo Romagnano
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3602 Visits: 3235
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.
Olga B
Olga B
Mr or Mrs. 500
Mr or Mrs. 500 (596 reputation)Mr or Mrs. 500 (596 reputation)Mr or Mrs. 500 (596 reputation)Mr or Mrs. 500 (596 reputation)Mr or Mrs. 500 (596 reputation)Mr or Mrs. 500 (596 reputation)Mr or Mrs. 500 (596 reputation)Mr or Mrs. 500 (596 reputation)

Group: General Forum Members
Points: 596 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 (540 reputation)Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)Mr or Mrs. 500 (540 reputation)

Group: General Forum Members
Points: 540 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