Unexpected SQL syntax error!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Neo

    Unexpected SQL syntax error!

    I posted this to microsoft.publi c.sqlserver.pro gramming, but no one
    could answer my question. So I think it is a good place to re-post my
    question here.

    My question:

    I found that if you do not include any effective SQL statement between
    BEGIN/END block, SQL Server 2000 Query Analyzer will think it is an
    error:

    Server: Msg 156, Level 15, State 1, Line 6
    Incorrect syntax near the keyword 'end'.

    if 1=1
    select getdate()
    else
    begin
    --select 'ok'
    end

    Is this behavior a SQL standard or simply a M$ standard glitch?
  • Trevor Best

    #2
    Re: Unexpected SQL syntax error!

    On 31 Aug 2003 22:41:51 -0700 in comp.databases. ms-sqlserver,
    neo_in_matrix@m sn.com (Neo) wrote:
    [color=blue]
    >I posted this to microsoft.publi c.sqlserver.pro gramming, but no one
    >could answer my question. So I think it is a good place to re-post my
    >question here.
    >
    >My question:
    >
    >I found that if you do not include any effective SQL statement between
    >BEGIN/END block, SQL Server 2000 Query Analyzer will think it is an
    >error:
    >
    >Server: Msg 156, Level 15, State 1, Line 6
    >Incorrect syntax near the keyword 'end'.
    >
    >if 1=1
    >select getdate()
    >else
    >begin
    >--select 'ok'
    >end
    >
    >Is this behavior a SQL standard or simply a M$ standard glitch?[/color]

    From books online:
    <--
    Syntax
    BEGIN
    { sql_statement | statement_block }
    END

    Arguments
    {sql_statement | statement_block }
    -->

    Shows the argument is not optional. :-)

    --
    A)bort, R)etry, I)nfluence with large hammer.

    (replace sithlord with trevor for email)

    Comment

    • Neo

      #3
      Re: Unexpected SQL syntax error!

      .......

      Can anyone direct me to other newsgroups for this question?

      neo_in_matrix@m sn.com (Neo) wrote in message news:<96aebc0f. 0308312141.6bd8 9e8c@posting.go ogle.com>...[color=blue]
      > I posted this to microsoft.publi c.sqlserver.pro gramming, but no one
      > could answer my question. So I think it is a good place to re-post my
      > question here.
      >
      > My question:
      >
      > I found that if you do not include any effective SQL statement between
      > BEGIN/END block, SQL Server 2000 Query Analyzer will think it is an
      > error:
      >
      > Server: Msg 156, Level 15, State 1, Line 6
      > Incorrect syntax near the keyword 'end'.
      >
      > if 1=1
      > select getdate()
      > else
      > begin
      > --select 'ok'
      > end
      >
      > Is this behavior a SQL standard or simply a M$ standard glitch?[/color]

      Comment

      • Steve Kass

        #4
        Re: Unexpected SQL syntax error!

        Was my answer not helpful?

        SK

        Neo wrote:[color=blue]
        > ......
        >
        > Can anyone direct me to other newsgroups for this question?
        >
        > neo_in_matrix@m sn.com (Neo) wrote in message news:<96aebc0f. 0308312141.6bd8 9e8c@posting.go ogle.com>...
        >[color=green]
        >>I posted this to microsoft.publi c.sqlserver.pro gramming, but no one
        >>could answer my question. So I think it is a good place to re-post my
        >>question here.
        >>
        >>My question:
        >>
        >>I found that if you do not include any effective SQL statement between
        >>BEGIN/END block, SQL Server 2000 Query Analyzer will think it is an
        >>error:
        >>
        >>Server: Msg 156, Level 15, State 1, Line 6
        >>Incorrect syntax near the keyword 'end'.
        >>
        >>if 1=1
        >>select getdate()
        >>else
        >>begin
        >>--select 'ok'
        >>end
        >>
        >>Is this behavior a SQL standard or simply a M$ standard glitch?[/color][/color]

        Comment

        • John Bell

          #5
          Re: Unexpected SQL syntax error!


          "Neo" <neo_in_matrix@ msn.com> wrote in message
          news:96aebc0f.0 308312141.6bd89 e8c@posting.goo gle.com...
          [color=blue]
          > Is this behavior a SQL standard or simply a M$ standard glitch?[/color]

          Having this message is not a bad thing as it tends to indicate that your
          code is incorrect, rather than the opposite.

          John


          Comment

          • Trevor Best

            #6
            Re: Unexpected SQL syntax error!

            On Tue, 02 Sep 2003 11:36:27 GMT in comp.databases. ms-sqlserver, Steve
            Kass <skass@drew.edu > wrote:
            [color=blue]
            >Was my answer not helpful?[/color]
            [color=blue]
            >Neo wrote:[color=green]
            >> ......
            >>
            >> Can anyone direct me to other newsgroups for this question?
            >>[/color][/color]

            or mine?

            consider changing:

            if @foo=1
            set @bar = 2
            else
            set @bar = 3

            to:
            if @foo=1
            set @bar = 2
            else
            -- set @bar = 3

            you'd get the same sort of error, unless of course some more code
            followed that bit in which case you'd just get unexpected results.

            --
            A)bort, R)etry, I)nfluence with large hammer.

            (replace sithlord with trevor for email)

            Comment

            Working...