June 10, 2008 at 12:44 pm
Hello,
Could someone please educate me on why each of the following two syntaxes would be better than the other:
SELECT SERVERPROPERTY('productlevel') mycolumnname
SELECT SERVERPROPERTY('productlevel') as [mycolumnname]
Thanks!
Gabor
June 11, 2008 at 1:47 am
In my openion, second one is better. The key word 'AS' serves as a hint. It is easy to guess that mycolumnname is an alias.
June 11, 2008 at 2:02 am
Second one...
It is having more clarity........
June 12, 2008 at 5:09 am
I agree the second one is much better on the eye
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
June 12, 2008 at 8:23 am
I agree mostly... the second one... just loose the square brackets for readability purposes and don't use aliases that require them with the rare exception being reporting queries.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 13, 2008 at 8:19 am
Just call me lazy to type but I always go for the first one, simply because repeating the word "as" it a lot of typing
But if I write a query that someone else is going to read, then I normally add the "as" so they can read a little better
~PD
June 13, 2008 at 10:24 am
I don't know... I hate them both...
I still like
SELECT
fieldname = a.field1,
fieldname2 = a.field2
FROM
table1 a
I know it's not perfect SQL syntax... but the = sign just feels more readable to me.
So your above would look like this.
SELECT mycolumnname = SERVERPROPERTY('productlevel')
June 13, 2008 at 12:07 pm
Now, I agree with THAT! That's my favorite format because it puts all of the aliases in the same position horizontally speaking AND it's the same format required by updates. Makes conversion of a SELECT for test to an actual UPDATE super easy, too!
Rumor has it that that form is being deprecated and I really, really wish they wouldn't remove it. Leave a good thing be... and, NO, I don't give a rat's patooti if it's ANSI or not.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 13, 2008 at 12:16 pm
Jeff Moden (6/13/2008)
Now, I agree with THAT! That's my favorite format because it puts all of the aliases in the same position horizontally speaking AND it's the same format required by updates. Makes conversion of a SELECT for test to an actual UPDATE super easy, too!Rumor has it that that form is being deprecated and I really, really wish they wouldn't remove it. Leave a good thing be... and, NO, I don't give a rat's patooti if it's ANSI or not.
I'm sure theres a way to petition to save it... if I had to go back to reading code looking for AS statements to find aliases again... I'd cry...
June 14, 2008 at 10:23 am
I prefer [font="courier new"]{expression} AS {columnAlias}[/font], but I suppose its just because I am used to it. I agree with Jeff though, only use the brackets1 when they are needed (column aliases that are keywords or that have non-alpha, non-numeric characters, such as space, etc.).
(1 It's just "brackets" as there aren't any non-square brackets. "Curly brackets" is a misnomer perpetuated on us by the Illiterati, their real name is "braces".)
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply