Chelsea
Chelsea

Reputation: 751

sql insert operation in stored procedure

I have a stored procedure for insert operation.I tried the following but it gives me error.

ALTER PROCEDURE SetStaffSalary
    @staffid int =0,
    @amount int = 0

AS
 SET NOCOUNT ON 

BEGIN
  begin
    insert into AccStaff (totalSalary) values (@amount) where fk_staffID = @staffid;
  end
END

gives error incorrect syntax near the keyword where.

Upvotes: 0

Views: 69

Answers (2)

muhamad ridwan
muhamad ridwan

Reputation: 156

there's no "where" on insert syntax. example :

insert into account (staffid, salary) values (@id, @salary);

or you could use update syntax to update the data.

update account set salary = @salary where staffid = @id;

Upvotes: 1

Dudi Konfino
Dudi Konfino

Reputation: 1136

try it like this - it looks like you want t do update

    ALTER PROCEDURE setstaffsalary @staffid int = 0 , 
                               @amount int = 0
AS
BEGIN
    UPDATE accstaff
    SET totalsalary = @amount
      WHERE fk_staffid
            = 
            @staffid;
END;

Upvotes: 0

Related Questions