すべてのフィードバックに感謝します。私の質問が理解しにくいことは承知していますが、友人の助けを借りて質問に答えることができます。必要なコードは次のとおりです。
USE [CCBBS_Survey_DB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SaveNewQuestionChoice]
@question VARCHAR(200),
@choice VARCHAR(100),
@qno INT,
@categid int,
@ratingid int
AS
BEGIN
IF NOT EXISTS(SELECT QuestionNo FROM CS_RefQuestions where QuestionNo = @qno)
BEGIN
INSERT INTO CS_RefQuestions(Question,QuestionNo,CategoryID, SetID)
VALUES (@question, @qno, @categid, 1)
END
ELSE
BEGIN
UPDATE CS_RefQuestions
SET Question = @question
,CategoryID = @categid
WHERE QuestionNo = @qno
END
DECLARE @QUI INT
SET @QUI = (SELECT TOP(1) QuestionID FROM CS_RefQuestions where QuestionNo = @qno)
INSERT INTO dbo.CS_RefQuestionChoice(ChoiceDescription, QuestionID, RatingID, SetID)
SELECT @choice, @QUI, @ratingid,1 FROM CS_RefQuestions RQ
WHERE QuestionID = @QUI
END