A simple trick for “Block Comment” syntax in SSMS

  • Comments posted to this topic are about the item A simple trick for “Block Comment” syntax in SSMS

  • Oh, I love this stuff.

    Thanks Zerko.

  • Wonderfull!

    You gave me a good Idea.

    😀

  • nice and simple trick.

    Thank you for sharing.

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • I use comments to test changes to parameterised stored procedures without having to create or alter the sproc first.

    /**/

    CREATE PROC Test @param1 INT, @param2 VARCHAR(20) AS

    --*/DECLARE @param1 INT/*

    --*/DECLARE @param2 VARCHAR(20)/*

    --*/

    SELECT @param1, @param2

    By breaking the close comment in the initial /**/ you coment out the CREATE (or ALTER) statement and uncomment the DECLARE statements.

    /**-/

    CREATE PROC Test @param1 INT, @param2 VARCHAR(20) AS

    --*/DECLARE @param1 INT/*

    --*/DECLARE @param2 VARCHAR(20)/*

    --*/

    SELECT @param1, @param2

  • This is exactly the technique I use in long 'utility' scripts and it works very well. I generally leave everything commented out until I need it, in case someone drops something on my F5 key :crazy:

    There is one additional thing I would like to be able to do though: select a block of text and then use a keyboard shortcut (like CTRL-K/CTRL-C) to automatically insert the /*[textblock]*/ around the block (/*[textblock]--*/ would be even better!).

    I wonder if anyone has tried to do this?

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • Neat trick.

    There is one additional thing I would like to be able to do though: select a block of text and then use a keyboard shortcut (like CTRL-K/CTRL-C) to automatically insert the /*[textblock]*/ around the block (/*[textblock]--*/ would be even better!).

    I wonder if anyone has tried to do this?

    All the built-in ways I could find on the various menus and such in SSMS (including stuff not shown by default) seem to use the double-dash type comment. I have heard about third-party add-ins that add macro capability to SSMS that might prove useful.

    ____________
    Just my $0.02 from over here in the cheap seats of the peanut gallery - please adjust for inflation and/or your local currency.

  • Thanks zerko!

  • lshanahan (7/8/2013)


    Neat trick.

    There is one additional thing I would like to be able to do though: select a block of text and then use a keyboard shortcut (like CTRL-K/CTRL-C) to automatically insert the /*[textblock]*/ around the block (/*[textblock]--*/ would be even better!).

    I wonder if anyone has tried to do this?

    All the built-in ways I could find on the various menus and such in SSMS (including stuff not shown by default) seem to use the double-dash type comment. I have heard about third-party add-ins that add macro capability to SSMS that might prove useful.

    The SSMSBoost add-in does it (along with some other neat stuff).

  • How about the comment toggle trick:

    -- Toggle trick

    SELECT 'Toggle line 1'/*

    SELECT 'Toggle line 2'--*/

    By commenting line 1 line 2 becomes active.

    Don't just give the hungry man a fish, teach him how to catch it as well.

    the sqlist

  • I hope I never have to inherit any of these scripts. It isn't exactly 'self documenting' to have nested commented code blocks that sometimes should run and other times should not run.

    For all the clever that went into manually comment in/out of code, you could probably have written a proper IF block. ex: IF !EXISTS(/* check for table */) begin /* create table, populate with data, etc. */ end <-- now instead of commenting, you can simply run & rerun the script without a comment block to explain when the comment block should or should not be [un]commented

    If you have any more dynamic manual craziness, don't stop at a clever commenting process: make it a working Stored Procedure. I don't have time to learn this 'convention' for commenting and manually running code. (who does?)

    That said, if you are talking about the process of developing/testing ad-hoc code that is en-route to becoming a real procedure... then thanks for the insight into your methodology. I feel like it is a bit too complicated for me to remember and use naturally.

    btw, thanks for writing the article too.

  • I use a slight variation:

    /* Explantory comment *

    Code

    --*/

    Note the asterisk at the end of the comment.

    I can follow that with a slash, and the code

    becomes effective, retaining the comment.

  • Very useful. I bet I do this all the time from now on.

  • Very useful tip. Thanks!

  • Superb development tool! I'd hate to need to work around this in live code though.

Viewing 15 posts - 1 through 15 (of 54 total)

You must be logged in to reply to this topic. Login to reply