create procedure InsertQuestionEntry
@round_name varchar(40),
@question varchar(100),
@answer varchar(40),
@option1 varchar(20),
@option2 varchar(30),
@option3 varchar(30)

as
begin
insert into QuestionEntry(Question,Round_Name) values(@question,@round_name);
declare @quesion_id int

exec @quesion_id= select Question_ID from QuestionEntry;

insert into Answer(Question_ID,Answer,Option1,Option2,Option3) values(@quesion_id,@answer,@option1,@option2,@option3);
end


在这里,我想从表Question_ID中检索QuestionEntry,并将该Question_ID用于另一个表Answer

但这没有用。

那么如何使用以上方法呢?

请帮我

最佳答案

代替

insert into QuestionEntry(Question,Round_Name) values(@question,@round_name);
declare @quesion_id int

exec @quesion_id= select Question_ID from QuestionEntry;


使用以下内容:

DECLARE @quesion_id int
INSERT INTO QuestionEntry(Question,Round_Name) values(@question,@round_name)
SET @quesion_id = SCOPE_IDENTITY()

10-08 06:50