By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Urgent; Incorrect Syntax Near Go Help

P: n/a
Hi Experts,
i am writting a stored procedure in sql server 7. Its a simple stored
procedure
It is my first stored procedure.
I want insert a record in table if the primary key field user id
already does not exists. if it exists SP should pass 0 as output else
if insert is successfull it should pass 1 to calling sp.
But following SP raising an ERRor" Incorrect Syntax near 'GO'
help
It is as follows

Create Procedure Sp_FillUserDetails
@UserId varchar(50),
@Password varchar(50),
@DOB DateTime,
@Gender varchar(6),
@Address varchar(250),
@City varchar(50),
@State varchar(20),
@Country varchar(20),
@ZIp varchar(15),
@Phone1 varchar(15),
@Mobile varchar(15),
@Email varchar(100),
@CCName varchar(25),
@CCno varchar(25),
@ExipiryDate DateTime,
@Question varchar(60),
@Answer varchar(50),
@Result int output

AS

If exists(Select * from Users where userid=@UserID)
set @Result=0
Else
Insert into Users (Userid, Password, dob, Gender, Address, City,
State, Country, Zipcode,Phone1, Mobile, EmailID, CCname, CCno,
expirydate, Question, Answer) values
(@UserId, @Password ,@DOB ,@Gender ,@Address ,@City ,@State ,@Country
,@ZIp ,@Phone1 ,@Mobile,@Email ,@CCName ,@CCno ,@ExipiryDate
,@Question ,@Answer)

set @result=0

GO
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Amit D.Shinde (am*******@yahoo.com) writes:
i am writting a stored procedure in sql server 7. Its a simple stored
procedure
It is my first stored procedure.
So that's why it's urgent?
I want insert a record in table if the primary key field user id
already does not exists. if it exists SP should pass 0 as output else
if insert is successfull it should pass 1 to calling sp.
But following SP raising an ERRor" Incorrect Syntax near 'GO'
help
It seems that somehow you are using a tool where GO is not a batch
terminator. GO is as far as SQL Server is concerned just another two-
letter identifier. Tools usually uses GO as a batch separator, which
means that if you have:

SELECT this FROM tbl
go
SELECT that FROM tbl
go
SELECT thisandthat FROM tbl

the tool will pass the three SELECT statements one at a time to SQL Server,
whereas if you remove the "go"s, SQL Server get all three statements at
once. In neither case, SQL Server will not see "go" itself.

Tip: if you are using Enterprise Manager to write your stored procedures,
stop doing that. Use Query Analyzer instead, since this is a far better
editor. (Although QA in SQL7 is a bit bleak compared to QA in SQL2000, as
I recall.)
Create Procedure Sp_FillUserDetails


Don't use sp_ in the name of your stored procedures. This prefix is
reserved for system procedures, and SQL Server first looks for such
procedure in the master database.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.