Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Incorrect syntax near 'GO'.

Author  Topic 

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-03-23 : 03:44:13
Hi All,
I am getting the below error message while executing the below mentioned script as a whole. but when I split the Drop part and GO part and Create Part seperately then its works fine. any Idea why the script is showing error message due to GO keyword.

Error msg :

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'GO'.
Msg 111, Level 15, State 1, Line 1
'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.



Proc which I used :
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ES_TestTable]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[ES_TestTable]

GO

CREATE PROC [dbo].[ES_TestTable]
(
@ErrorCode varchar(512) = Null OUTPUT
)
AS
BEGIN
SET NOCOUNT ON

BEGIN TRY

SELECT [id],
[name]
FROM TestTable

END TRY

BEGIN CATCH
SET @ErrorCode = CHAR(10) + 'Error while retrieving Testtable.'
RETURN
END CATCH

SET NOCOUNT OFF

END


Karthik
http://karthik4identity.blogspot.com/

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-03-23 : 04:07:58
I just ran this on my system and it works perfectly with no changes whatsoever. Everything ran in one batch. Are you sure this is the exact script that is being executed? How are you executing it?

- Lumbago
If the facts don't fit the theory, change the facts. Albert Einstein
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-03-23 : 04:14:20
Lumbago,
Thanks for the Reply,I executed the same script and get error
The code is correct but I guess some settings has been changed so that it is not using the GO statement in my machine. any Idea..?

Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-03-23 : 04:17:09
and also when I use GO in other case like.

select 10
GO
select 20

then the resut is

GO
-----------
10

(1 row(s) affected)


-----------
20

(1 row(s) affected)

the keyword GO has become the column header.

Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-23 : 04:21:06
In the menu Goto Query-->Query Options
Check what the Batch seperator is under Execution-->General

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-03-23 : 04:23:13
quote:
Originally posted by madhivanan

In the menu Goto Query-->Query Options
Check what the Batch seperator is under Execution-->General

Madhivanan

Failing to plan is Planning to fail


I have cheked that
The batch separator is GO

Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-23 : 04:26:56
It is becuase GO is not in the seperate line
Put it in seperate line and see what happens

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-03-23 : 04:29:53
quote:
Originally posted by madhivanan

It is becuase GO is not in the seperate line
Put it in seperate line and see what happens

Madhivanan

Failing to plan is Planning to fail



Thanks for your reply,
I have tested it Its in the seperate line only.
but still I guess It could be settings Problem.

Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-03-23 : 07:09:00
quote:
Originally posted by karthik_padbanaban

quote:
Originally posted by madhivanan

In the menu Goto Query-->Query Options
Check what the Batch seperator is under Execution-->General


I have cheked that
The batch separator is GO



Clear the text box and retype "GO" in it, or click the Reset to Default button on the Query Options dialog.

There are 10 types of people in the world, those that understand binary, and those that don't.
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-03-23 : 07:18:29
quote:
Originally posted by DBA in the making

quote:
Originally posted by karthik_padbanaban

quote:
Originally posted by madhivanan

In the menu Goto Query-->Query Options
Check what the Batch seperator is under Execution-->General


I have cheked that
The batch separator is GO



Clear the text box and retype "GO" in it, or click the Reset to Default button on the Query Options dialog.

There are 10 types of people in the world, those that understand binary, and those that don't.



No this didnt worked.

Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-03-23 : 08:13:37
Buggered if I know. Are you having this problem when logged into the server, or a remote machine?

There are 10 types of people in the world, those that understand binary, and those that don't.
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-03-23 : 08:41:16
quote:
Originally posted by DBA in the making

Buggered if I know. Are you having this problem when logged into the server, or a remote machine?

There are 10 types of people in the world, those that understand binary, and those that don't.


I am logging in my local machine not in Remote


Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-03-23 : 08:52:39
Just to be sure you are using this from SSMS?

From DOCs: "GO is not a Transact-SQL statement; it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor"
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-03-23 : 08:59:24
quote:
Originally posted by Kristen

Just to be sure you are using this from SSMS?

From DOCs: "GO is not a Transact-SQL statement; it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor"


Ya I am very much sure about using SSMS.


Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-03-23 : 09:05:06
If it's happening on a remote machine, that only has SSMS installed (ie, not SQL Server), then I'd try logging into the server, or another client machine with SSMS, and see if the problem exists there as well (I can't see why it would, as the GO statement is handled locally by the SSMS, not by the server, by try it anyway). If it doesn't, then uninstall and re-install SSMS.

There are 10 types of people in the world, those that understand binary, and those that don't.
Go to Top of Page

karthik_padbanaban
Constraint Violating Yak Guru

263 Posts

Posted - 2010-03-23 : 09:27:50
quote:
Originally posted by DBA in the making

If it's happening on a remote machine, that only has SSMS installed (ie, not SQL Server), then I'd try logging into the server, or another client machine with SSMS, and see if the problem exists there as well (I can't see why it would, as the GO statement is handled locally by the SSMS, not by the server, by try it anyway). If it doesn't, then uninstall and re-install SSMS.

There are 10 types of people in the world, those that understand binary, and those that don't.



I think It would be a settings problem.

Karthik
http://karthik4identity.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-23 : 09:59:05
Are you sure you are connected to correct server?
Try closing SSMS and see if you get error again

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Lijo Cheeran Joseph
Posting Yak Master

123 Posts

Posted - 2011-06-19 : 04:34:51
I too have similar problem.. The batch separator is "GO". I opened the query in Management Studio after going into the server.

There is a DROP temp table statement just before the END of an SP. I pressed enter after the DROP statement and wrote GO. It says "Incorrect syntax near '#tempZipCodeUpload'."

Note: When I type the following in a separate window; it works fine; the column headers are 'No Column Name'
select 10
GO
select 20

Any editor available to create the correct new line?

Any thoughts?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-06-19 : 08:09:39
quote:
Originally posted by Lijo Cheeran Joseph

I too have similar problem.. The batch separator is "GO". I opened the query in Management Studio after going into the server.

There is a DROP temp table statement just before the END of an SP. I pressed enter after the DROP statement and wrote GO. It says "Incorrect syntax near '#tempZipCodeUpload'."

Note: When I type the following in a separate window; it works fine; the column headers are 'No Column Name'
select 10
GO
select 20

Any editor available to create the correct new line?

Any thoughts?


You should open a new thread AND show your code AND show the complete error message.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

mkkwan00
Starting Member

1 Post

Posted - 2012-12-04 : 22:28:37
u copy and paste ur string to notepad.. if u see the go is within a same line or not ?

E.g use testgo etc..

if yes, then manually edit on the notepad and copy back to SSMS
Go to Top of Page

Law2rence
Starting Member

6 Posts

Posted - 2012-12-11 : 08:45:57
Thanks for the Reply,I executed the same script and get error



Go to Top of Page
    Next Page

- Advertisement -