<\/script>')

Sybase: Incorrect syntax next to "go" in "IF EXISTS" block

This is my sql statement

IF EXISTS (select 1 from sysobjects where name = 'PNL_VALUE_ESTIMATE') drop table dbo.PNL_VALUE_ESTIMATE go 

isql gives an error message

 Msg 102, Level 15, State 1: Server 'DB_SERVER', Line 3: Incorrect syntax near 'go'. 

But the sql expression looks correct for me. What's wrong?

Sybase version is 15

+4
source share
4 answers

Try the following:

 IF EXISTS (select 1 from sysobjects where name = 'PNL_VALUE_ESTIMATE') drop table dbo.PNL_VALUE_ESTIMATE go 

or that:

 IF EXISTS (select 1 from sysobjects where name = 'PNL_VALUE_ESTIMATE') BEGIN drop table dbo.PNL_VALUE_ESTIMATE END go 

or that:

 IF EXISTS (select 1 from sysobjects where name = 'PNL_VALUE_ESTIMATE') BEGIN select 1 END go 

Does any work work?

+1
source

GO not a T-SQL keyword, but an editor.

SMSS (between others) uses it as a โ€œseparationโ€ between batches of commands that it sends to the database server. Executing it inside a stored procedure or even a script file will not work.

edit: It may work with SyBase, but I think that in this case it should be uppercase.

0
source

From the documentation, the GO statement is the command of the editor used, not SQL :

GO is not a Transact-SQL statement; it is a team recognized by sqlcmd and the osql utility and SQL Server Management Studio code editor.

However, Sybase is also an editor that supports the GO statement.

I had the same problem but with SQL Management Studio. The problem is that the editor does not support mixed-line types around certain statements - GO is one of them. In Management Studio, for example, only Windows-style lines (CR + LF) are allowed, and if I used the Linux (LF) format, it would produce the same error as yours.

In text editors such as Notepad ++ (which I use), there is an option for what type of trailing characters you use by default (Windows, Linux, Mac (CR)).

Try checking which newlines are used in your instructions to determine if this can solve the problem.

0
source

Should an object reference have

dbo..PNL_VALUE_ESTIMATE

because you did not specify the database name, and if you included the obj owner, you need to ... skip the db name?

I would go:

EXEC ('DROP TABLE dbo..PNL_VALUE_ESTIMATE')

in the true part, since DROP TABLE is always compiled, and if the table does not exist, you will still fail.

Do you even need a dbo? If your sql always works like dbo, just leave it.

-1
source

Source: https://habr.com/ru/post/1389596/


All Articles