Stored Proc error caused by comments and SYSCOMMENTS

  • I remember seeing something about this recently, but I'm not sure it was here.  I was performing cleanup on a new stored procedure and got a syntax error on an END statement.  But I hadn't changed any logic.  I finally traced it down to the following snippet of code:

       WHILE @@fetch_status <> -1 --File_cur

        BEGIN

    --   If we got ...

    The error occured when I removed the blank line between the WHILE and the BEGIN.

    I remember that the problem has to do with how the procedure is stored in syscomments and that essentially what happened was that the BEGIN ended up being commented out as part of the "-- File_cur" comment on the preceding line.  But I don't remember specifically whats going on.  Can someone enlighten me on exactly what is happening here?

    Thanks!

    Steve

  • I don't know. (to be clear)

    But here's my guess:

    I suspect the editor that you used to create the proc stripped the line breaks in a manner that confused the parser.

    In old DOS days, line breaks are a combo of char(13) + char(10).  (In unix I think it's char(10)?)

    In the old days SQL server treated any white space the same equating tabs, spaces and line breaks, and only parsing based on key words.  With SQL92 (?) somebody decided '--' was a good idea (don't look at me).  So then to handle that the parser had to understand '--' as the begin of a comment and line break as an end of comment.  And this is the first time line break became important to the parser.  And with microsoft's track record of lazy assed development they probably don't handle it well. (I can't not miss a chance to dis MS).

    So my guess is your editor or tool writing your proc isn't putting a form of line break in that MS wants to see.

     

     

  • John,

    Thank you for your response.  I think you are probably right.  One caveat... The editor that I used was........drum roll.....Microsoft SQL Server 2000 Query Analyzer!

    Steve

  • I was able to duplicate your problem when using only a CHAR(13) as a line break.

Viewing 4 posts - 1 through 3 (of 3 total)

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