Groups | Blog | Home
all groups > sql server (alternate) > november 2004 >

sql server (alternate) : Urgent; Incorrect Syntax Near Go Help



amit_sd01 NO[at]SPAM yahoo.com
11/21/2004 7:52:48 AM
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

Erland Sommarskog
11/21/2004 5:18:12 PM
Amit D.Shinde (amit_sd01@yahoo.com) writes:
[quoted text, click to view]

So that's why it's urgent?

[quoted text, click to view]

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.)

[quoted text, click to view]

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, esquel@sommarskog.se

Books Online for SQL Server SP3 at
AddThis Social Bookmark Button