Я могу что-то упустить, но почему этот бит не работает вне курсора, если вы извлекаете @QuestionId из предложения where?:
--check if @isMulti is true or not
if(@isMulti=1)
begin
update tblAnswers
set col1 = 1, col2 = 1, col3 = (select count(*) from tblAnswers where ID=@ID)
end
else if(@isMulti=0)
begin
update tblAnswers
set col1 = AnswerID, col2 = 1, col3 = (select LEN(count(*)) from tblAnswers where ID=@ID)
end
EDIT
Не зная больше о метаданных, я не уверен, как обработать многоэлементный вопрос, но это должен быть хороший способ ответа:
declare @question table (questionid int, multi int)
declare @answer table (answerid int, col1 int, col2 int, col3 int)
insert into @question (questionid, multi) values (1, 0)
insert into @question (questionid, multi) values (2, 0)
insert into @question (questionid, multi) values (3, 0)
insert into @question (questionid, multi) values (4, 1)
insert into @question (questionid, multi) values (5, 1)
insert into @answer (answerid, col1, col2, col3) values (1, 0, 0, 0)
insert into @answer (answerid, col1, col2, col3) values (1, 0, 0, 0)
insert into @answer (answerid, col1, col2, col3) values (2, 0, 0, 0)
insert into @answer (answerid, col1, col2, col3) values (2, 0, 0, 0)
insert into @answer (answerid, col1, col2, col3) values (3, 0, 0, 0)
insert into @answer (answerid, col1, col2, col3) values (4, 0, 0, 0)
insert into @answer (answerid, col1, col2, col3) values (4, 0, 0, 0)
insert into @answer (answerid, col1, col2, col3) values (4, 0, 0, 0)
insert into @answer (answerid, col1, col2, col3) values (5, 0, 0, 0)
update @answer
set col1 = 1, col2 = 1, col3 = (select count(*) from @answer a join @question q on a.answerid = q.questionid where q.multi = 0 and [@answer].answerid = a.answerid)
select distinct * from @answer