all groups > sql server (alternate) > august 2003 >
You're in the

sql server (alternate)

group:

Unexpected SQL syntax error!



Unexpected SQL syntax error! neo_in_matrix NO[at]SPAM msn.com
8/31/2003 10:41:51 PM
sql server (alternate): 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

Re: Unexpected SQL syntax error! Trevor Best
9/1/2003 8:33:09 AM
On 31 Aug 2003 22:41:51 -0700 in comp.databases.ms-sqlserver,
[quoted text, click to view]

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.

Re: Unexpected SQL syntax error! neo_in_matrix NO[at]SPAM msn.com
9/1/2003 9:22:20 PM
.......

Can anyone direct me to other newsgroups for this question?

[quoted text, click to view]
Re: Unexpected SQL syntax error! Steve Kass
9/2/2003 11:36:27 AM
Was my answer not helpful?

SK

[quoted text, click to view]
Re: Unexpected SQL syntax error! John Bell
9/2/2003 12:58:25 PM

[quoted text, click to view]

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

John

Re: Unexpected SQL syntax error! Trevor Best
9/2/2003 9:36:49 PM
On Tue, 02 Sep 2003 11:36:27 GMT in comp.databases.ms-sqlserver, Steve
[quoted text, click to view]

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.

AddThis Social Bookmark Button