Question

I learn to use stored procedure for insert, but I get this error

incorrect syntax near DECLARE

I don't understand much about syntax, please help to correct it and explain it for me too;

USE P_DETAIL

CREATE PROCEDURE PRO_INSERT DECLARE 
@ST_ID int,
@ST_NAME NVARCHAR(50),
@ST_SEX NVARCHAR(10),
@ST_DOB DATE,
@ST_AGE INT,
@ST_POSITION NVARCHAR(30),
@ST_ADDRESS NVARCHAR(60),
@ST_PHONE INT,
@SV_ID INT,
BEGIN

INSERT INTO TBL_STAFF
(
ST_ID ,
ST_NAME ,
ST_SEX ,
ST_DOB ,
ST_AGE ,
ST_POSITION ,
ST_ADDRESS ,
ST_PHONE ,
SV_ID 
)
VALUES
(
@ST_ID ,
@ST_NAME ,
@ST_SEX ,
@ST_DOB ,
@ST_AGE ,
@ST_POSITION ,
@ST_ADDRESS ,
@ST_PHONE ,
@SV_ID 
)

END;
Was it helpful?

Solution

Change the line CREATE PROCEDURE PRO_INSERT DECLARE to CREATE PROCEDURE PRO_INSERT AS. Then declare each variable, like this:

USE P_DETAIL

CREATE PROCEDURE PRO_INSERT 
AS
DECLARE
... --List of variables and procedure code 

One more thing - you need to remove the comma after @SV_ID INT, since that is the last parameter in your input parameters list.

Check out this sample Fiddle to see where your code is going wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top