sql error?

dkim18
dkim18 used Ask the Experts™
on
IF EXISTS (SELECT * FROM tblxxxx )
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ')'.


this statement is fine but above line gives me an error.
Why?
SELECT * FROM tblxxxx
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
IF EXISTS (SELECT * FROM tblxxxx where field=@ID)

Author

Commented:
I fixed it.

I forgot if GO is not allowed in the stored procedure.
Is that right?

I had

Create procedure
as
Begin
if exists()
begin

end
go
END
Anuradha GoliSystems Development / Support Specialist
Commented:
if EXISTS (SELECT * FROM tblxxxx)
  Print 'Record exists'
ELSE
  Print 'Record doesn''t exist'

Open in new window


Needs some statements to proceed further cant leave if exists alone.
Hope this resolved your issue.

Author

Commented:
I just realize that GO is not a part of Tsql
Sr. Software Engineer
Commented:
if you run just following code (in SQL Query Analyzer), it will work.

IF EXISTS (SELECT * FROM tblxxxx )
SELECT * FROM tblxxxx;

GO isn't a TSQL command. It marks the end of a batch in Query Analyzer and
therefore signals the end of a stored procedure definition in that batch, so
it cannot be part of an SP.

HTH
Ashok

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial