wood burning stoves 2.0
The moose likes JDBC and Relational Databases and the fly likes SQL Sysntax Error. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL Sysntax Error." Watch "SQL Sysntax Error." New topic

SQL Sysntax Error.

ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
Can anyone please help me out below is the stored procedure and error.
I am using Sybase BUT when i run this on SQL Server 2000 it works fine no error. But on Sybase it is throwing an error please help me out.
This is second time i ve posted this.

Create Procedure spGetMaximumVersionForid
@id int

Select id,Version = IsNull(Max(Ver),0)
Select id,Ver = Max(Version)
From ModifiedForm
Group By id
Select id,Ver = Max(Version)
From ReqForm
Group By id
) As DT
Where id= @id
Group By id


Server Message: Number 156, Severity 15
Incorrect syntax near the keyword 'Select'.
Server Message: Number 102, Severity 15
Incorrect syntax near ')'.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

It's likely nobody answered because they didn't know. It certainly looks right to me.

Try a standard troubleshooting trick to narrow down the problem: see how much of the stored proc you can remove and still get the compiler error. Often doing this helps see it better. Once you do that, you may see it yourself. If not, post the simplified stored proc in this thread.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
Thanks Jeanne , it is fine on SQL Server but NOT when i run it on Sybase. anyway thanks.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1141

I don't have an answer for you, and please forgive me if this is a silly question, but I don't know Sybase nor SQL Server and I am curious.

For your procedure to work in both databases, both databases would need to have identical syntax. Are you sure that they do?

In my experience with Oracle and Informix databases, the syntax used for writing stored procedures in those two databases is totally different. There is no way I could run an Oracle stored procedure in an Informix database -- and vice-versa.

The error message you are getting seems to indicate that Sybase and SQL Server do, indeed, use different syntax for defining stored procedures. So I repeat, why do you think the exact same procedure definition should work in both Sybase and SQL Server?

Good Luck,
vernon mweetwa

Joined: Nov 26, 2004
Posts: 24

I totally agree with Avi on what he is saying, meaning the syntax of using certain key words like SELECT maybe different because of different vendors. Try to check on a simplified way of how Sybase uses the SELECT word and from there you will find the solution. It is rare to find the same SQL script running the same way on different databases without making a few changes to form to the new type of database.
ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
thanks all of you for giving me a good suggestion..
I agree. Here's the link: http://aspose.com/file-tools
subject: SQL Sysntax Error.
It's not a secret anymore!