Help with this Stored proc
-
I am trying to get the questionID from two different Select statements and then insert into a table one by one. DECLARE @NewID INT This one is inserting a new surveyID, Output is SurveyID insert into survey(title,description, surveystatus,CreatedBy,date ) values('New Survey','New Survey',1,'test',Getdate()) SELECT @NewID = SCOPE_IDENTITY() Copying the questions with the new surveyID INSERT SurveyQuestions(surveyid, questions,answertype) SELECT @NewID ,questions,answertype FROM SurveyQuestions WHERE surveyid='81' The problem is below here. I want to get the value of the questionId of the first select statement then the value of the questionID of the second select statement and insert into the table SurveyChoices one by one. Both the select statements can have 1 or 2 or 3 rows or more but the both the select statements will have exact number of rows. select QuestionId from surveyquestions where surveyid=@NewID and answertype <> 'T' select QuestionId from surveyquestions where surveyid='81' and answertype <> 'T' Here i am using the insert statement using the value form First select statement and second select statement INSERT Surveychoices(QuestionId,choice) SELECT questionID,choice((This is the value of the First select statement.) FROM Surveychoices WHERE questionid=questionID(This is the value of the second select statement.)