我的存储过程不起作用,我收到错误:
Msg 102,Level 15,State 1,Procedure SP_HUGO_INSRTGAME,Line 4
'@firstName'附近的语法不正确。
消息137,级别15,状态1,程序SP_HUGO_INSRTGAME,第12行
必须声明标量变量“@StudentFirstName” 消息102,级别15,状态1,程序SP_HUGO_INSRTGAME,第13行
'value'附近的语法不正确。
这是我的存储过程:
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
答案 0 :(得分:3)
程序中有很多错误:
第一:在定义参数时,每个参数后都必须有一个逗号
第二:您只是将@StudentFirstName
设置为字符串值,但它是一个int。从字符串我得到的是,您首先插入行,然后将最近插入的行的ID添加到@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 @StudentFirstName = SCOPE_IDENTITY()
使用它你将得到id然后你可以做
insert into tbl_hugo_game (user_hugo_Id) values (@StudentFirstName )
完成。
答案 1 :(得分:-1)
insert into tbl_hugo_game (user_hugo_Id) values (@StudentFirstName )
答案 2 :(得分:-1)
Create Procedure SP_HUGO_INSRTGAME
@lastName as nvarchar(200),
@firstName as nvarchar(200),
@email as nvarchar(200)
As
Declare @StudentFirstName Int
Begin
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()
insert into tbl_hugo_game (user_hugo_Id) values (@StudentFirstName )
End