Do you have a comment or suggestion to improve SQL Server? We’d love to hear it!

"GO" in 2nd half of nested block comments breaks batch parsing in SSMS and SQLCMD

If a "GO" batch separator is embedded in the second half of nested block comments (i.e. anywhere after the first "*/" and before the final "*/" ),
the batch parsing breaks in both SSMS and SQLCMD. While embedded blocks comments are accepted by SQL Server, the batch parsing
(just the part that splits a script into multiple batches) of both of these clients (and possibly also SMO) does not truly accept nested block
comments and assumes that the block comment has ended upon seeing the first "*/". ALSO, the position of the initial "/*" makes a difference
in that if the "/" of the start of the block comment is the first character on the line (position 1) then the errors will happen, but if there are
one or more spaces or tabs before the "/", then the parser works correctly. Meaning:

Works: /* GO first /* middle */ last */
Works: /* first /* GO middle */ last */
ERROR: /* first /* middle */ GO last */
Works: /* first /* middle1 */ /* GO middle2 */ last */
Works: /* first /* middle1 */ /* middle2 */ GO last */
ERROR: /* first /* middle1 *//* middle2 */ GO last */

There are 3 additional cases shown in the SQL scripts attached to this ticket that cannot be expressed on a single line like the variations shown above.

For what it's worth, OSQL does not have this bug, but had another which errors on embedded batch separators if they were the first thing on the line.

2 votes
Sign in
Password icon
Signed in as (Sign out)

We’ll send you updates on this idea

AdminMicrosoft SQL Server (Product Manager, Microsoft Azure) shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →


Sign in
Password icon
Signed in as (Sign out)
  • Solomon Rutzky commented  ·   ·  Flag as inappropriate

    This is still an issue for SSMS v18.0 RC1 (SQL Server Management Studio 15.0.18098.0).

    ALSO, to clarify the originally stated test cases above: the two cases that produce an error (the 3rd and 6th examples) only produce the error IF they start at the FIRST character position of the line. If you add any white-space to the beginning of the line, then they parse correctly. Along these lines, I tried a variation of the 6th example, spread across multiple lines. It also gets an error, but it's different as there are now two errors:

    /* first /* middle1 *//* middle2
    last */

    Msg 113, Level 15, State 1, Line XXXXX (line with GO)
    Missing end comment mark '*/'.
    Msg 102, Level 15, State 1, Line XXXXX + 1 (line after GO)
    Incorrect syntax near '*'.

    P.S. It would be super great if this horribly inadequate UserVoice system actually allowed us to post code that would preserve spacing, etc. Come on, it's 2019 already and nearly every other site out there has been able to do this basic stuff for years. There are open-source libraries for processing mark-down, so there is really no excuse for this site being 10 - 15 years behind the rest of the world.

  • Solomon Rutzky commented  ·   ·  Flag as inappropriate

    This is still an issue for SSMS v18.0 Preview 7 (SQL Server Management Studio 15.0.18092.0).

    I have not tested in the newest SQLCMD that should come with SQL Server 2019 CTP 2.3, but I assume it uses the same parsing logic and would thus have the same issue.

Feedback and Knowledge Base