• That seems quite a bit more complicated than this:

    CREATE PROCEDURE [dbo].[setTodoSequence]

    (

    @personID int,

    @todoID as int,

    @todoSequence as smallint

    )

    AS

    SET NOCOUNT ON;

    declare @oldTodoSequence smallint

    declare @direction smallint

    declare @start smallint

    declare @end smallint

    -- get the old sequence

    set @oldTodoSequence = (select todoSequence from dbo.ToDoList where todoID = @todoID);

    SET @direction = Sign(@todosequence - @oldtoDoSequence)

    SELECT @start = CASE WHEN @direction = -1 then @todosequence ELSE @oldtodosequence END

    , @end = CASE WHEN @direction = -1 then @oldtodosequence ELSE @todosequence END

    update todolist

    set todosequence = CASE WHEN todoid = @todoID THEN @todoSequence ELSE todosequence - @direction END

    where todosequence between @start and @end

    and personId = @personid