SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Incorrect syntax near 'GO'.
 New Topic  Reply to Topic
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

karthik_padbanaban
Constraint Violating Yak Guru

India
263 Posts

Posted - 03/23/2010 :  03:44:13  Show Profile  Reply with Quote
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

Norway
3271 Posts

Posted - 03/23/2010 :  04:07:58  Show Profile  Reply with Quote
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

India
263 Posts

Posted - 03/23/2010 :  04:14:20  Show Profile  Reply with Quote
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

India
263 Posts

Posted - 03/23/2010 :  04:17:09  Show Profile  Reply with Quote
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

India
22761 Posts

Posted - 03/23/2010 :  04:21:06  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

India
263 Posts

Posted - 03/23/2010 :  04:23:13  Show Profile  Reply with Quote
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

India
22761 Posts

Posted - 03/23/2010 :  04:26:56  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

India
263 Posts

Posted - 03/23/2010 :  04:29:53  Show Profile  Reply with Quote
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 - 03/23/2010 :  07:09:00  Show Profile  Reply with Quote
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

India
263 Posts

Posted - 03/23/2010 :  07:18:29  Show Profile  Reply with Quote
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 - 03/23/2010 :  08:13:37  Show Profile  Reply with Quote
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

India
263 Posts

Posted - 03/23/2010 :  08:41:16  Show Profile  Reply with Quote
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

United Kingdom
22403 Posts

Posted - 03/23/2010 :  08:52:39  Show Profile  Reply with Quote
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

India
263 Posts

Posted - 03/23/2010 :  08:59:24  Show Profile  Reply with Quote
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 - 03/23/2010 :  09:05:06  Show Profile  Reply with Quote
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

India
263 Posts

Posted - 03/23/2010 :  09:27:50  Show Profile  Reply with Quote
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

India
22761 Posts

Posted - 03/23/2010 :  09:59:05  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

Edited by - madhivanan on 03/23/2010 10:00:27
Go to Top of Page

Lijo Cheeran Joseph
Posting Yak Master

123 Posts

Posted - 06/19/2011 :  04:34:51  Show Profile  Reply with Quote
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?

Edited by - Lijo Cheeran Joseph on 06/19/2011 04:39:13
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 06/19/2011 :  08:09:39  Show Profile  Visit webfred's Homepage  Reply with Quote
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

Singapore
1 Posts

Posted - 12/04/2012 :  22:28:37  Show Profile  Reply with Quote
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

USA
6 Posts

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




Edited by - Law2rence on 12/11/2012 08:53:54
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000