Gar!!! Really odd syntax error

  • I've been pulling my hair out for well over an hour trying to figure out an error in a sql script.  It got to the point where I was going to post a cleaned up / genericised version to here.  Well, in doing so, the error went away.

    This, of course, called for a new process of elimination.  What was different?  Tried several things to no avail.  The last thing I was left with was the comments / version history header that is standard issue for this site (which I'd removed from the cleaned up version).  Ta Da!  The error went away.  BUT... I can't leave the comments off.  So what in the world could it be?  Everything looked fine and was color-coded correctly (using SSMS query editor). 

    I noticed that there was a machine-generated comment (/* notes here */) embedded within the comments header (which was also using the /* nnn */ syntax).  Took out the machine-generated comment and now everything is now fine and dandy.

    Of course, the error had absolutely nothing related to what was actually the issue.

    Just thought I'd share in case anyone else stumbles upon this.

  • Was it like this

    /* comment

    /* machine comment*/

    */

    ?

    _____________
    Code for TallyGenerator

  • Or something like this?

    /* comment blah blah

       blah blah

       this works

    */

    select getdate()

    /* comment blah blah

       blah blah

       this will bomb due to the below batchterminator, even when it's inside the comment (but as the lone word on the row)

    go

    */

    select getdate()

    /* comment blah blah

       blah blah

       this works when it's commented out by row

    --go

    */

    select getdate()

    /* comment blah blah

       blah blah

       this also works...

    go west

    */

    select getdate()

    Did you have a 'go' anywhere in the comment, as the only word on a row?

    /Kenneth

     

  • It was more like Sergiy's example. 

    Although it's interesting that Kenneth mentioned the GO command, as that is what the compiler was having issues with.  (Except they well were outside of the comments area.)

    in rough pseudocode:

    IF

    OBJECT_ID('MyProc') IS NOT NULL

    DROP

    PROCEDURE MyProc

    GO

     

    Create

    Proc MyProc (

    @my_id

    char(10)

    )

    As

    Begin

    /* Version Control Information

    ** blah blah

    ** ns /* machine gen comt that caused the woes */ notes

    ** more notes

    ** more text

    */

    select * from tables

    select * from tables

    End

    GO

    grant execute on MyProc to developer

    GO

    (yields incorrect syntax near grant and incorrect syntax near go messages)

  • Well, the thing about nested comments -

    /* Version Control Information

    ** blah blah

    ** ns /* machine gen comt that caused the woes */ notes

    ** more notes

    ** more text

    */

    ..is that the colorcoding breaks after the first */ and you said in the original post that the coding was fine all the way. At least it breaks in SS2k QA..

    /Kenneth

  • That color coding was mine to highlight the issue.  In SSMS it doesn't break.

  • To expand on the above comments, v9 supports nested comments. But v8 recognises */ and not /* inside a comment block. Once a /* is encountered, further /* s are ignored (treated as comment text) until the comment is closed, which occurs at the very first */ . So in

    /*   This  isa huamn coment, !!  Hear is the machine coment:
     
      /*unknown error at line .*/
      wELL, now for teh code!!!
    */

    the second /* is ignored, and the second */ is found to be unmatched. I seem to remember that -- behaves in a similar way, so:

    --/* test 2.1.x: start of commented out block
    select blah from anyoldwhere
    --/* test 2.2.x: start of commented out block
    select gubbins from oojahmeflip
    --   test 2.x: end of commented block*/

    would work OK, but

    /*
    --/* test 2.1.x: start of commented out block
    select wassname from thingybob
    --/* test 2.2.x: start of commented out block
    select thingummyjig from twiddlededee
    --   test 2.x: end of commented block*/
    */

    would fail since there are two effective */ s, for one effective /* . The embedded -- s are rendered ineffective by the opening /* , so the first */ closes the comment as before.

    Tim Wilkinson

    "If it doesn't work in practice, you're using the wrong theory"
    - Immanuel Kant

Viewing 7 posts - 1 through 6 (of 6 total)

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