<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx</link><description>I was checking my Twitter feed on my way in to work this morning and was alerted to an interesting blog post by Valentino Vranken that highlights a problem regarding the OLE DB Source in SSIS. In short, using double-dash comments in SQL statements within</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46533</link><pubDate>Thu, 06 Dec 2012 09:34:33 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46533</guid><dc:creator>Koen Verbeeck</dc:creator><description>&lt;p&gt;I always use double dash, so I guess it's time to start changing my habits :)&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46534</link><pubDate>Thu, 06 Dec 2012 10:11:57 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46534</guid><dc:creator>Dave Ballantyne</dc:creator><description>&lt;p&gt;Maybe i should look at my TSQL Smells project taking apart a dtsx package also as it can already detect these in .sql scripts :)&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://tsqlsmells.codeplex.com/"&gt;http://tsqlsmells.codeplex.com/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46535</link><pubDate>Thu, 06 Dec 2012 10:49:01 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46535</guid><dc:creator>Mikael Eriksson</dc:creator><description>&lt;p&gt;Unless you need to comment out some XML code that uses /* in the XPath expression.&lt;/p&gt;
&lt;p&gt;&amp;lt;pre&amp;gt;&lt;/p&gt;
&lt;p&gt;select @XML.value('.', 'int')&lt;/p&gt;
&lt;p&gt;from @XML.nodes('/root/*[@ID = 1]') as T(N)&lt;/p&gt;
&lt;p&gt;&amp;lt;/pre&amp;gt;&lt;/p&gt;
&lt;p&gt;Then you need to use the double dashes.&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46536</link><pubDate>Thu, 06 Dec 2012 12:22:06 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46536</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Sorry, but this is totally off the mark. Inline comments are easier to use, maintain, and even to read for small comments. Plus they don't create a comment block, and that's a plus when you need to later comment out larger chunks of code.&lt;/p&gt;
&lt;p&gt;Don't abandon tools due to perceived weakness. Just as you wouldn't abandon a hammer due to its lack of utility as a screwdriver. Figure out, instead, the appropriate time and place for everything.&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46537</link><pubDate>Thu, 06 Dec 2012 12:59:50 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46537</guid><dc:creator>jamiet</dc:creator><description>&lt;p&gt;Adam,&lt;/p&gt;
&lt;p&gt;Each to their own. If there are good arguments for and against then I hope people have the good sense to take both arguments on board before deciding what they want to do.&lt;/p&gt;
&lt;p&gt;JT&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46540</link><pubDate>Thu, 06 Dec 2012 13:43:36 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46540</guid><dc:creator>Mike Woodburne</dc:creator><description>&lt;p&gt;Adam and Mikael both have very good points - the double dash comment has a purpose and it shouldn't be discarded as being dangerous, especially because of a product bug.&lt;/p&gt;
&lt;p&gt;Also, unless I am missing some clever trolling or delicious irony, Chris Adkin's slide not only offers up a poor reason for not using the double dash (any good statement can become useless because of an accidental backspace), but it also contains a spelling error when countering the argument for good code review (an error which would have been caught during a review).&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46541</link><pubDate>Thu, 06 Dec 2012 14:30:57 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46541</guid><dc:creator>jamiet</dc:creator><description>&lt;p&gt;Hi Mike,&lt;/p&gt;
&lt;p&gt;Thanks for the comment.&lt;/p&gt;
&lt;p&gt;No clever trolling or irony intended. Yes, Chris' slide contained a spelling error but I wasn't going to not post it because of that. Hopefully Chris will come here and reply to your belief that he offered a poor reason for not using double dash.&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Jamie&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46542</link><pubDate>Thu, 06 Dec 2012 15:33:02 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46542</guid><dc:creator>Chris Adkin</dc:creator><description>&lt;p&gt;Mike,&lt;/p&gt;
&lt;p&gt;As per Jamie's comment, &amp;quot;Each to their own&amp;quot;. However, I do know for a fact that there have been instances where code has gone bang in production because of lines being back spaced onto preceding lines containing '--' comments by mistake. Also, and you can put this down to my own personal preference, I think /* */ comment blocks are more readable. As for your comment about trolling, I'm not sure where this comes from. Another point I would make, and again this is regarding readability, and again, before anyone shoots me down in flames you can attribute this to my own personal preference, is that I often see people use '--' style cooments where by you have to scroll a considerable distance to the right of the screen to see what the comment text actually is. In my humble opinion, the use of /* */ style comments is more conducive to readable code in this specific case. Thanks for the point about the typo, I hadn't noticed this and I will correct it. I would suspect that the spirit of Jamie's post was intended to reflect the fact that '--' can be dangerous and was not intended to out right castigate anyone that uses these. Conversely I have seen people comment out whole blocks of code with /* */ which is also bad, such code, again IMHO, should never make it into production. I never suspected that comment styles would illicit such strong opinions, temp tables versus table variables perhaps . . .&lt;/p&gt;
&lt;p&gt;Chris&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46546</link><pubDate>Thu, 06 Dec 2012 17:25:27 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46546</guid><dc:creator>Cliff</dc:creator><description>&lt;p&gt;I prefer using a stored procedure as the source if there is anything more than a simple select. If it is a simple select with maybe a few joins, I will place comments in the annotation next to the OLE SRC if needed.&lt;/p&gt;
&lt;p&gt;I also agree that &amp;quot;someone might hit backspace and hose code&amp;quot; is not, IMO, a good reason to not use the double dash. If the developer is testing code, and code is being locked down, then this will be caught long before it gets to production. In terms of portability, I believe there are some SQL engines that do not support /* */ commenting. Of course, I could be wrong on that last point.&lt;/p&gt;
&lt;p&gt;All that being said, I use both styles. If it's a simple comment, I will use the double dash. If it's going to need a paragraph then I will use the comment block style. &lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46547</link><pubDate>Thu, 06 Dec 2012 17:27:37 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46547</guid><dc:creator>Valentino Vranken</dc:creator><description>&lt;p&gt;On the comment-style usage topic, I'm using both all the time. As Adam said, they both have their good uses!&lt;/p&gt;
&lt;p&gt;Having said that, the bug has been filed: &lt;a rel="nofollow" target="_new" href="https://connect.microsoft.com/SQLServer/feedback/details/773689/ssis-ole-db-source-incorrectly-returns-zero-records-in-combination-with-parameter-and-comment"&gt;https://connect.microsoft.com/SQLServer/feedback/details/773689/ssis-ole-db-source-incorrectly-returns-zero-records-in-combination-with-parameter-and-comment&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46553</link><pubDate>Fri, 07 Dec 2012 01:55:37 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46553</guid><dc:creator>Marcus van Raalte</dc:creator><description>&lt;p&gt;I just read this advice and this is my first time reading a SQLblog.com entry that i said NO!&lt;/p&gt;
&lt;p&gt;Thanks you Adam Machanic for your comment&lt;/p&gt;
&lt;p&gt;The problem with /**/ style comments, that means we must be careful with them also, are 2 fold&lt;/p&gt;
&lt;p&gt;1) If there is a big block of comments, finding the start and end of a block can be a challenge&lt;/p&gt;
&lt;p&gt;2) You cannot have 1 set embedded in another, this limitation can result in difficult find compile SQL errors.&lt;/p&gt;
&lt;p&gt;My default advice to juniors, or non-SQL developers is to use the double dash by default. The reason is that they are &amp;quot;in your face&amp;quot; at the begining of each line of SQL code, easy and obvious.&lt;/p&gt;
&lt;p&gt;Typing errors can cause all sorts of problems and the fear of them should not be the basis for defining coding best practise when using the alternatives has bigger issues to worry about.&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46558</link><pubDate>Fri, 07 Dec 2012 18:09:12 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46558</guid><dc:creator>mst</dc:creator><description>&lt;p&gt;Well...&lt;/p&gt;
&lt;p&gt;[irony]I think the solution, then, is NO comments.[/irony] Because in SSMS for SQL2005, we encountered this:&lt;/p&gt;
&lt;p&gt;I tried to modifiy a USP; SSMS pops up a dialog: &lt;/p&gt;
&lt;p&gt;Script failed for StoredProcedure 'dbo.uspUhoh'. (Microsoft.SqlServer.Smo)&lt;/p&gt;
&lt;p&gt;Additional information:&lt;/p&gt;
&lt;p&gt;Syntax error in TextHeader of StoredProcedure 'uspUhoh'. (Microsoft.SqlServer.Smo) &lt;/p&gt;
&lt;p&gt;We were in the middle of a server issue-- and when I hit THIS I was concerned we may have had a db problem. I punted to the developer to do some checking.&lt;/p&gt;
&lt;p&gt;His conclusion was that it was caused by nested comments before the ALTER PROCEDURE statement-- here was his sample:&lt;/p&gt;
&lt;p&gt;SET ANSI_NULLS ON&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;SET QUOTED_IDENTIFIER ON&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;/*&lt;/p&gt;
&lt;p&gt;So it is okay to have one level of comments...&lt;/p&gt;
&lt;p&gt;It is not okay /* to have more than one embedded */ C-Style /* comments like these */&lt;/p&gt;
&lt;p&gt;Though, strangly one set of embedded C-Style comments is, apparently, okay. Two are not.&lt;/p&gt;
&lt;p&gt;-- These style are okay to embed&lt;/p&gt;
&lt;p&gt;*/&lt;/p&gt;
&lt;p&gt;ALTER PROCEDURE dbo.uspUhoh&lt;/p&gt;
&lt;p&gt;AS&lt;/p&gt;
&lt;p&gt;BEGIN&lt;/p&gt;
&lt;p&gt;-- your code&lt;/p&gt;
&lt;p&gt;END&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46560</link><pubDate>Fri, 07 Dec 2012 20:55:13 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46560</guid><dc:creator>Cliff</dc:creator><description>&lt;p&gt;I don't think a valid solution to not using the comment block properly is to just not put in any comments. That's like refusing to walk because you tripped once.&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46561</link><pubDate>Fri, 07 Dec 2012 21:13:44 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46561</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Cliff,&lt;/p&gt;
&lt;p&gt;Pretty sure mst was making some attempt at humor.&lt;/p&gt;
&lt;p&gt;By the way, to those who believe in banning inline comments due to some tiny potential for error: this same argument would have to apply to any language that supports such comments. So what you're really implying is that virtually every language ever created got this wrong. Sorry, but I'll have to take the side of the language designers in that particular battle.&lt;/p&gt;
&lt;p&gt;By the way, this reminds me of a manager I once had who banned us from using the ternary operator in C++ programs, because once he had accidentally misread one and introduced an error in some program. There is such a thing as acceptable risk, and both inline comments and ternary operators have very low, very reasonable thresholds.&lt;/p&gt;
&lt;p&gt;--Adam&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46585</link><pubDate>Mon, 10 Dec 2012 18:09:23 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46585</guid><dc:creator>CodePro</dc:creator><description>&lt;p&gt;Actually, my goal is always to make my code as self-documenting as possible, Zen-like. When I insert a comment, I am acknowledging failure.&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46603</link><pubDate>Tue, 11 Dec 2012 01:14:09 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46603</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;CodePro: I've heard that lots and lots of times. And it doesn't work. Use comments, please.&lt;/p&gt;
</description></item><item><title>re: The perils of double-dash comments [T-SQL]</title><link>http://www2.sqlblog.com/blogs/jamie_thomson/archive/2012/12/06/the-perils-of-double-dash-comments-t-sql.aspx#46631</link><pubDate>Wed, 12 Dec 2012 15:42:45 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46631</guid><dc:creator>Larry Leonard</dc:creator><description>&lt;p&gt;CodePro - Code cannot be made self-documenting. &amp;nbsp;Code always answers the question &amp;quot;How?&amp;quot;, but can never the question &amp;quot;Why?&amp;quot;. &amp;nbsp;This is a problem, as anyone can (eventually) understand *how* a piece of code works; understanding *why* the code is doing it requires comments.&lt;/p&gt;
&lt;p&gt;In other, more Zen-like words, just because the cat has her kittens in the oven doesn't make them biscuits. &amp;nbsp;Code is code: it cannot be made more than it is.&lt;/p&gt;
</description></item></channel></rss>