感谢所有的反馈,非常感谢。我知道我的问题很难理解,但是我可以在朋友的帮助下回答我的问题。这是我需要的代码:
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