Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««123

Views Expand / Collapse
Author
Message
Posted Wednesday, April 21, 2010 4:25 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:31 AM
Points: 11,194, Visits: 11,137
Hugo Kornelis (4/21/2010)
I never understand that habit. The semicolon is a statement terminator, not a statement starter, so the logical place for it is at the end of a statement, not before the next one.

This is one of those (perhaps irrational) things that bothers me too - it makes my brain jolt every time I see that ;WITH construction used. On the other hand, I dislike column lists prefixed with a comma (though I do see why people do that) as well, so maybe it is just me.




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #908198
Posted Wednesday, April 21, 2010 4:43 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, August 1, 2014 9:46 PM
Points: 1,380, Visits: 2,684
Paul White NZ (4/21/2010)
Hugo Kornelis (4/21/2010)
I never understand that habit. The semicolon is a statement terminator, not a statement starter, so the logical place for it is at the end of a statement, not before the next one.

This is one of those (perhaps irrational) things that bothers me too - it makes my brain jolt every time I see that ;WITH construction used. On the other hand, I dislike column lists prefixed with a comma (though I do see why people do that) as well, so maybe it is just me.


I'm on the fence with the comma prefix. I definately have been using the ; at the end of the code block althought It still isn't a habbit and sometimes I forget to do it.; (lol)


---------------------------------------------------------------------
Use Full Links:
KB Article from Microsoft on how to ask a question on a Forum
Post #908207
Posted Wednesday, April 21, 2010 4:58 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 3:27 PM
Points: 21,631, Visits: 15,289
Paul White NZ (4/21/2010)
Hugo Kornelis (4/21/2010)
I never understand that habit. The semicolon is a statement terminator, not a statement starter, so the logical place for it is at the end of a statement, not before the next one.

This is one of those (perhaps irrational) things that bothers me too - it makes my brain jolt every time I see that ;WITH construction used. On the other hand, I dislike column lists prefixed with a comma (though I do see why people do that) as well, so maybe it is just me.


I'm one who likes to have the comma in front of the column in a list. I do it for ease of commenting out a line if I decide that column should not be included without having to comment out a comma somewhere else. Though - if people were consistent with their commas it wouldn't matter too much and things would line up more neatly.




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #908217
Posted Friday, April 23, 2010 10:10 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Today @ 12:51 PM
Points: 21, Visits: 720
The question is misleadingly worded. A view definition can contain a CTE, but the CTE is not "part of" the SELECT statement. The CTE can contain its own SELECT statement, and can precede the defining SELECT statement of the view.
Post #909649
Posted Monday, May 3, 2010 5:27 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, July 15, 2014 4:53 AM
Points: 2,366, Visits: 1,844
learnt something new.

"Keep Trying"
Post #914587
Posted Tuesday, July 27, 2010 9:01 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Today @ 4:54 PM
Points: 8,689, Visits: 9,223
Hugo Kornelis (4/21/2010)
I never understand that habit. The semicolon is a statement terminator, not a statement starter, so the logical place for it is at the end of a statement, not before the next one.

The semicolon has always been part of the Transact SQL syntax, but unlike almost every other language, it was optional.

Can you suggest a language in which it is used as a terminator rather than as a separator? I can't think of one.

I remember the early C++ compilers (the ones which compiled C++ into C and then called a C compiler to get a binary) which were sensitive to the fact that it was not a terminator, but a separator, and didn't like empty statements. So if you wrote a semicolon at the end of the last statement before the terminating brace of a compound statement the parser threw an error. You also got an error if you wrote a semicolon after the closing brace of a compound statement.

Is T-SQL going to break with this tradition and allow semicolon immediately before or immediately after END?
And hence, nobody ever used it. This first changed when the SQL Server 2005 parser required a statement to be terminated in order to recognise WITH as the CTE starter, not as a query hint.

And that was a bad piece of language design. If the parser team were unable conveniently to distinguish the two uses of "WITH" (which suggests either incompetence or unreasonable schedule presure) they should have insisted on a different keyword being used for CTEs, to preserve the language's ability to live without a statement separator.
But in SQL Server 2008, the SQL team went a step further and added "Not using a statement terminator for Transact-SQL statements" to the list of deprecated features. This means that in some future version, you will be required to terminate all statements.

I can't think of a polite way to express my opinion of this MS decision.
So do as I do - start to accustom yourself to terminating all statements with a semicolon today. You'll be thankful later. (And you'll never have to worry about the semicolon before a CTE anymore).

I probably won't do that. I'm old enough that I could happily stop using T-SQL when that change comes in. I'm already getting hell from my wife because I'm trying to work for 8 to 16 weeks a year instead of retiring completely, so doing a couple of weeks on non-database stuff instead of a few months on database when this nonsense kicks in a a few years time might benefit me more from the reduction in nagging I get than it costs me from the loss of fun things to do, so I could stick instead to my beloved declarative (functional, logical, or mathematical) languages which don't need statement separators because each has a decent syntax. And finding 4 weeks work in one of those areas will probably be about as easy as finding 16 weeks as a data management expert.


Tom
Post #959808
Posted Sunday, August 1, 2010 3:32 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 5:28 PM
Points: 5,969, Visits: 8,224
Tom.Thomson (7/27/2010)
Hugo Kornelis (4/21/2010)
I never understand that habit. The semicolon is a statement terminator, not a statement starter, so the logical place for it is at the end of a statement, not before the next one.

The semicolon has always been part of the Transact SQL syntax, but unlike almost every other language, it was optional.

Can you suggest a language in which it is used as a terminator rather than as a separator? I can't think of one.

I remember the early C++ compilers (the ones which compiled C++ into C and then called a C compiler to get a binary) which were sensitive to the fact that it was not a terminator, but a separator, and didn't like empty statements. So if you wrote a semicolon at the end of the last statement before the terminating brace of a compound statement the parser threw an error. You also got an error if you wrote a semicolon after the closing brace of a compound statement.

Is T-SQL going to break with this tradition and allow semicolon immediately before or immediately after END?


Yes. The semicolon is a terminator in T-SQL, not a seperator. This is valid code:
IF @Var = 1
BEGIN;
PRINT 'It is 1';
END;
ELSE
BEGIN;
PRINT 'It is not 1';
END;

There is no semicolon after IF @Var = 1 or after ELSE because they need a statement (or a BEGIN END block) to be complete.

There is one annoying exception - in a TRY CATCH block, you get an error when you terminate END TRY with a semicolon.

I don't know enough about C++ to comment about the terminator / seperator difference, so I'll just take your word for it.

And hence, nobody ever used it. This first changed when the SQL Server 2005 parser required a statement to be terminated in order to recognise WITH as the CTE starter, not as a query hint.

And that was a bad piece of language design. If the parser team were unable conveniently to distinguish the two uses of "WITH" (which suggests either incompetence or unreasonable schedule presure) they should have insisted on a different keyword being used for CTEs, to preserve the language's ability to live without a statement separator.

Only they could not use anything but WITH for the CTE start, because that is how a CTE is defined in the ANSI standard for SQL. And they could not change the use of WITH for hints either, cause that would break existing code.



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #961938
Posted Saturday, November 3, 2012 3:15 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, July 25, 2014 12:34 AM
Points: 1,888, Visits: 2,326
Nice and clean question..
Good discussion



_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1380689
Posted Thursday, January 31, 2013 5:53 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, August 18, 2014 3:26 AM
Points: 262, Visits: 232
nice question.... Easy understandable about both view and CTE....






Manik
**********


Manik
You cannot get to the top by sitting on your bottom.
Post #1414039
« Prev Topic | Next Topic »

Add to briefcase «««123

Permissions Expand / Collapse