I'm attempting to send in a number and identifiers and update rows in a while loop.
For instance if @Number = 1
and
MAX(Number)
FROM QuestionnaireQuestions
WHERE Questionnaire_ID = @Questionnaire_ID = 4
The results are values 1, 1, 1 when I would expect 3,2,1.
CREATE PROCEDURE [dbo].[DeleteQuestion]
(@QuestionnaireQuestions_ID BIGINT,
@Questionnaire_ID BIGINT,
@Number SMALLINT)
AS
DECLARE @i AS SMALLINT
SELECT @i = MAX(Number)
FROM QuestionnaireQuestions
WHERE Questionnaire_ID = @Questionnaire_ID
WHILE ( @i > @Number )
BEGIN
UPDATE QuestionnaireQuestions
SET Number = ( @i - 1 )
WHERE Number = @i
AND Questionnaire_ID = @Questionnaire_ID
SET @i = @i - 1
END
DELETE QuestionnaireQuestions
WHERE QuestionnaireQuestions_ID = @QuestionnaireQuestions_ID