471,108 Members | 1,264 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,108 software developers and data experts.

Unexpected SQL syntax error!

Neo
I posted this to microsoft.public.sqlserver.programming, 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?
Jul 20 '05 #1
5 9015
On 31 Aug 2003 22:41:51 -0700 in comp.databases.ms-sqlserver,
ne***********@msn.com (Neo) wrote:
I posted this to microsoft.public.sqlserver.programming, 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?


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)
Jul 20 '05 #2
Neo
.......

Can anyone direct me to other newsgroups for this question?

ne***********@msn.com (Neo) wrote in message news:<96**************************@posting.google. com>...
I posted this to microsoft.public.sqlserver.programming, 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?

Jul 20 '05 #3
Was my answer not helpful?

SK

Neo wrote:
......

Can anyone direct me to other newsgroups for this question?

ne***********@msn.com (Neo) wrote in message news:<96**************************@posting.google. com>...
I posted this to microsoft.public.sqlserver.programming, 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?


Jul 20 '05 #4

"Neo" <ne***********@msn.com> wrote in message
news:96**************************@posting.google.c om...
Is this behavior a SQL standard or simply a M$ standard glitch?


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

John
Jul 20 '05 #5
On Tue, 02 Sep 2003 11:36:27 GMT in comp.databases.ms-sqlserver, Steve
Kass <sk***@drew.edu> wrote:
Was my answer not helpful? Neo wrote:
......

Can anyone direct me to other newsgroups for this question?


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)
Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Jim Michaels | last post: by
20 posts views Thread by Jim Michaels | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.