File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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
Bookmark "SQL Sysntax Error." Watch "SQL Sysntax Error." New topic
Author

SQL Sysntax Error.

ghazanfar khan
Ranch Hand

Joined: Apr 18, 2005
Posts: 81
Hello,
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
As

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

GO
=================================

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

Joined: May 26, 2003
Posts: 29241
    
139

Ghazanfar,
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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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: 1121

Khan,
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,
Avi.
vernon mweetwa
Greenhorn

Joined: Nov 26, 2004
Posts: 24
Khan,

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.
 
Similar Threads
Sybase Error Msg
someone please help me out with this thing
getting last row
Selecting the last record in the table using Hibernate
insert query for mysql convert() using the tomcat