Question

Can anyone help me out?

I don't know why the following SQL gives a syntax error:

if not exists (select 1 from sysobjects where type='U' and name='pg_result')
    create table pg_result (parent char(10), child char(10)) 
else
    delete from pg_result
end if

I'm getting the following error:

[Error] Script lines: 141-146

Incorrect syntax near the keyword 'end'.

Msg: 156, Level: 15, State: 2

Server: SYBDEV, Line: 5

I'm running:

Adaptive Server Enterprise/12.5.4/EBF 16785 ESD#10/P/Sun_svr4/OS 5.8/ase1254/2159/64-bit/FBO/Mon Nov 2 13:08:08 2009

Any ideas please?

Was it helpful?

Solution

try

if not exists (select 1 from sysobjects where type='U' and name='pg_result')
    create table pg_result (parent char(10), child char(10)) 
else
    delete from pg_result

or

if not exists (select 1 from sysobjects where type='U' and name='pg_result')
begin
    create table pg_result (parent char(10), child char(10)) 
end
else
begin
    delete from pg_result
end

see http://infocenter.sybase.com/help/topic/com.sybase.help.ase_15.0.commands/html/commands/commands61.htm

OTHER TIPS

You don't need the end if you don't use a begin

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top