My stored procedure won’t work, I get an error :
Msg 102, Level 15, State 1, Procedure SP_HUGO_INSRTGAME, Line 4
Incorrect syntax near ‘@firstName’.
Msg 137, Level 15, State 1, Procedure SP_HUGO_INSRTGAME, Line 12
Must declare the scalar variable “@StudentFirstName”.
Msg 102, Level 15, State 1, Procedure SP_HUGO_INSRTGAME, Line 13
Incorrect syntax near ‘value’.
Here’s my stored procedure:
Create Procedure SP_HUGO_INSRTGAME
(
@lastName as nvarchar(200)
@firstName as nvarchar(200)
@email as nvarchar(200)
@StudentFirstName INT
)
As
Begin
SET @StudentFirstName = 'insert into tbl_hugo_user (user_email, first_name, last_name, confidence, inspire, creativity, bonus_q ) values (@email, @firstName, @lastName, 0, 0, 0, 0); SELECT SCOPE_IDENTITY() ';
insert into tbl_hugo_game (user_hugo_Id) value (@StudentFirstName )
End
You have lots of errors in the procedure:
First: when defining the parameters there has to be a comma after every parameter
Second: You are just setting the
@StudentFirstNamethe string value but it is an int. From the string I get that you are first inserting the row and then getting the ID of that recently inserted row to the@StudentFirstName. For that you have to do something like this:insert into tbl_hugo_user (user_email, first_name, last_name, confidence, inspire, creativity, bonus_q ) values (@email, @firstName, @lastName, 0, 0, 0, 0)SELECT @StudentFirstName = SCOPE_IDENTITY()using that you will get the id and then you can do
insert into tbl_hugo_game (user_hugo_Id) values (@StudentFirstName )to finish off.