• Thanks a lot for coming forward to help. I really appreciate that. Here are the insert statements. And the values I pass to procedure is (21,20,5). Please let me know, if need any other details.

    CREATE TABLE [dbo].[test](

    [id_task] [int] NULL,

    [id_fathertask] [int] NULL,

    [level_task] [int] NULL,

    [duracion_task] [float] NULL,

    [percent_task] [float] NULL,

    [name_task] [nvarchar](50) NULL,

    [Imm_value] [int] Null

    );

    insert into [dbo].[test]

    values

    (1,1,1,76,NULL,'Task 1',25),

    (2,1,2,60,NULL,'Task,1.1',38),

    (3,2,3,2,100,'Task,1.1.1',100),

    (4,2,3,38,NULL,'Task,1.1.2',44),

    (5,4,4,10,100,'Task,1.1.2.1',100),

    (6,4,4,22,20,'Task,1.1.2.2',20),

    (7,4,4,5,35,'Task,1.1.2.3',35),

    (8,4,4,1,40,'Task,1.1.2.4',40),

    (9,2,3,20,NULL,'Task,1.1.3',20),

    (10,9,4,20,20,'Task,1.1.3.1',20),

    (11,1,2,9,NULL,'Task,1.2',39),

    (12,11,3,2,0,'Task,1.2.1',0),

    (13,11,3,7,NULL,'Task,1.2.2',50),

    (14,13,4,2,50,'Task,1.2.2.1',50),

    (15,13,4,5,50,'Task,1.2.2.2',50),

    (16,1,2,10,0,'Task,1.3',0),

    (17,1,2,20,0,'Task,1.4',0),

    (18,1,2,6,NULL,'Task,1.5',10),

    (19,18,3,6,NULL,'Task,1.5.1',10),

    (20,19,4,6,NULL,'Task,1.5.1.1',10),

    (21,20,5,6,10,'Task,1.5.1.1.1',10);