Lord Byron
Lord Byron

Reputation: 167

Getting error Incorrect syntax near the keyword 'BEGIN' when executing stored procedure

So, I'm new to MS SQL (have been using oracle for the last 5-7 years) and this should be very a straight forward thing to do, so I reckon I'm missing something very simple. (I've tried following the examples here: http://technet.microsoft.com/en-us/library/ms190669(v=SQL.105).aspx)

So, I create the following stored procedure to query a table (this is a very simple and pointless procedure but I can't proceed with my more complex procedure until I resolve this problem)

create procedure sp_getTransactions
as
select * from MyTransactions;

I then try to execute this procedure

execute dbo.sp_getTransactions

(I've tried without the dbo. and get the same error)

This gives me the very helpful error Incorrect syntax near the keyword 'BEGIN'.

Now, maybe I'm crazy but I don't see a begin statement anywhere in my procedure (I've tried adding one to no avail).

Can anyone give me some pointers here? Thanks

Upvotes: 1

Views: 7554

Answers (2)

Lord Byron
Lord Byron

Reputation: 167

Actually, the problem as it turns out is the client I was using. I was executing the sql scripts using Oracle's SQLDeveloper with the MSSQL jTDS driver. It seems this driver works fine for the most part, but when it comes to running stored procedures there's a bug. I guess the execute statement isn't parsed properly by the plugin when being set to the server

Upvotes: 8

Jesuraja
Jesuraja

Reputation: 3844

Check like this:

CREATE PROCEDURE sp_getTransactions
AS
BEGIN
    SELECT * FROM MyTransactions;
END

In execute dbo.sp__getTransactions statement, you used 2 _, but in CREATE PROCEDURE statement it has only one. Change to dbo.sp_getTransactions and try to execute.

Upvotes: 0

Related Questions